Skip to content

Commit

Permalink
Merge pull request #69 from akeneo/fix-unused-required-command
Browse files Browse the repository at this point in the history
Fix unused requirement command
  • Loading branch information
pierallard authored Sep 9, 2022
2 parents b028c73 + 074ec74 commit 8141a08
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
7 changes: 0 additions & 7 deletions spec/RuleBuilderSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/Domain/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions src/RuleBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand Down

0 comments on commit 8141a08

Please sign in to comment.