Skip to content

Commit

Permalink
Prevent duplicate namespaces in ResideInOneOfTheseNamespaces (#431)
Browse files Browse the repository at this point in the history
* Prevent duplicate namespaces in ResideInOneOfTheseNamespaces

* Add test

* Reindex namespaces

---------

Co-authored-by: Herberto Graca <[email protected]>
  • Loading branch information
marmichalski and hgraca authored May 16, 2024
1 parent 204026e commit 00ef56a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ResideInOneOfTheseNamespaces implements Expression

public function __construct(string ...$namespaces)
{
$this->namespaces = $namespaces;
$this->namespaces = array_values(array_unique($namespaces));
}

public function describe(ClassDescription $theClass, string $because): Description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,14 @@ public function test_it_should_check_multiple_namespaces_in_or(): void
$haveNameMatching->evaluate($classDesc, $violations, $because);
self::assertNotEquals(0, $violations->count());
}

public function test_duplicate_namespaces_are_removed(): void
{
$expression = new ResideInOneOfTheseNamespaces('A', 'B', 'A', 'C', 'D', 'D');

self::assertSame(
'should reside in one of these namespaces: A, B, C, D because rave',
$expression->describe(ClassDescription::getBuilder('Marko')->build(), 'rave')->toString()
);
}
}

0 comments on commit 00ef56a

Please sign in to comment.