diff --git a/spec/RuleBuilderSpec.php b/spec/RuleBuilderSpec.php index d742e30..2d1af37 100644 --- a/spec/RuleBuilderSpec.php +++ b/spec/RuleBuilderSpec.php @@ -14,13 +14,6 @@ function it_is_initializable() $this->shouldHaveType(RuleBuilder::class); } - function it_does_not_create_a_rule_without_constraints() - { - $this - ->shouldThrow(new \Exception('Can not create a rule without any requirement defined previously.')) - ->during('in', ['baz']); - } - function it_chains_the_methods_for_building_a_rule() { $this->forbids(['foo', 'bar'])->shouldReturn($this); diff --git a/src/Domain/Rule.php b/src/Domain/Rule.php index a6d808d..5b97305 100644 --- a/src/Domain/Rule.php +++ b/src/Domain/Rule.php @@ -84,6 +84,10 @@ public function getUnusedRequirements(array $nodes): array return $this->matches($node); }); + if ([] === $matchingNodes) { + return []; + } + return array_filter($this->requirements, function (string $requirement) use ($matchingNodes) { if ($this->subject === $requirement) { return false; diff --git a/src/RuleBuilder.php b/src/RuleBuilder.php index f9a7c96..c1b5368 100644 --- a/src/RuleBuilder.php +++ b/src/RuleBuilder.php @@ -52,10 +52,6 @@ public function discourages(array $requirements): RuleBuilder public function in(string $subject): RuleInterface { - if (empty($this->requirements)) { - throw new \Exception('Can not create a rule without any requirement defined previously.'); - } - if (null === $this->type) { throw new \Exception('Can not create a rule without any type defined previously.'); }