From 2541826f6dfd7517bfe0d1f2d03a20f50b257e29 Mon Sep 17 00:00:00 2001 From: Herberto Graca Date: Sat, 16 Sep 2023 17:39:33 +0100 Subject: [PATCH 1/3] Prevent duplicate namespaces in ResideInOneOfTheseNamespaces --- src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php b/src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php index 5048486d..92578b71 100644 --- a/src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php +++ b/src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php @@ -18,7 +18,7 @@ class ResideInOneOfTheseNamespaces implements Expression public function __construct(string ...$namespaces) { - $this->namespaces = $namespaces; + $this->namespaces = array_unique($namespaces); } public function describe(ClassDescription $theClass, string $because): Description From f3826fe6c70a2e4465545f3ac8c0c22dd5df7f48 Mon Sep 17 00:00:00 2001 From: Marcin Michalski Date: Wed, 8 May 2024 21:56:41 +0100 Subject: [PATCH 2/3] Add test --- .../ForClasses/ResideInOneOfTheseNamespacesTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Unit/Expressions/ForClasses/ResideInOneOfTheseNamespacesTest.php b/tests/Unit/Expressions/ForClasses/ResideInOneOfTheseNamespacesTest.php index 95b526ff..4f8dce9e 100644 --- a/tests/Unit/Expressions/ForClasses/ResideInOneOfTheseNamespacesTest.php +++ b/tests/Unit/Expressions/ForClasses/ResideInOneOfTheseNamespacesTest.php @@ -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() + ); + } } From 2631ba6112d29872b71b9aad9edd02125d072092 Mon Sep 17 00:00:00 2001 From: Marcin Michalski Date: Wed, 8 May 2024 21:56:48 +0100 Subject: [PATCH 3/3] Reindex namespaces --- src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php b/src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php index 92578b71..4b5978ba 100644 --- a/src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php +++ b/src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php @@ -18,7 +18,7 @@ class ResideInOneOfTheseNamespaces implements Expression public function __construct(string ...$namespaces) { - $this->namespaces = array_unique($namespaces); + $this->namespaces = array_values(array_unique($namespaces)); } public function describe(ClassDescription $theClass, string $because): Description