Skip to content

Commit 3461695

Browse files
committed
Remove silent deduplication from all namespace expressions
All four Reside/NotReside namespace expressions now consistently assign the $namespaces array directly without array_unique(). The previous deduplication was undocumented defensive coding added inconsistently only to the positive variants, with no real use case behind it. https://claude.ai/code/session_01Hyx6VbsyC9RHb57zSuPamr
1 parent 84ff2e0 commit 3461695

6 files changed

Lines changed: 4 additions & 36 deletions

src/Expression/ForClasses/NotResideInOneOfTheseNamespacesExactly.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class NotResideInOneOfTheseNamespacesExactly implements Expression
1818

1919
public function __construct(string ...$namespaces)
2020
{
21-
$this->namespaces = array_values(array_unique($namespaces));
21+
$this->namespaces = $namespaces;
2222
}
2323

2424
public function describe(ClassDescription $theClass, string $because): Description

src/Expression/ForClasses/NotResideInTheseNamespaces.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class NotResideInTheseNamespaces implements Expression
1818

1919
public function __construct(string ...$namespaces)
2020
{
21-
$this->namespaces = array_values(array_unique($namespaces));
21+
$this->namespaces = $namespaces;
2222
}
2323

2424
public function describe(ClassDescription $theClass, string $because): Description

src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ResideInOneOfTheseNamespaces implements Expression
1818

1919
public function __construct(string ...$namespaces)
2020
{
21-
$this->namespaces = array_values(array_unique($namespaces));
21+
$this->namespaces = $namespaces;
2222
}
2323

2424
public function describe(ClassDescription $theClass, string $because): Description

src/Expression/ForClasses/ResideInOneOfTheseNamespacesExactly.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ResideInOneOfTheseNamespacesExactly implements Expression
1818

1919
public function __construct(string ...$namespaces)
2020
{
21-
$this->namespaces = array_values(array_unique($namespaces));
21+
$this->namespaces = $namespaces;
2222
}
2323

2424
public function describe(ClassDescription $theClass, string $because): Description

tests/Unit/Expressions/ForClasses/NotResideInOneOfTheseNamespacesExactlyTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,6 @@ public function test_it_should_return_false_if_reside_in_exact_namespace(): void
5252
);
5353
}
5454

55-
public function test_it_should_deduplicate_namespaces(): void
56-
{
57-
$haveNameMatching = new NotResideInOneOfTheseNamespacesExactly('MyNamespace', 'MyNamespace');
58-
59-
$classDesc = ClassDescription::getBuilder('MyNamespace\HappyIsland', 'src/Foo.php')->build();
60-
$because = 'we want to add this rule for our software';
61-
$violations = new Violations();
62-
$haveNameMatching->evaluate($classDesc, $violations, $because);
63-
64-
self::assertEquals(1, $violations->count());
65-
self::assertEquals(
66-
'should not reside in one of these namespaces exactly: MyNamespace because '.$because,
67-
$haveNameMatching->describe($classDesc, $because)->toString()
68-
);
69-
}
70-
7155
public function test_it_should_check_multiple_namespaces_in_or(): void
7256
{
7357
$haveNameMatching = new NotResideInOneOfTheseNamespacesExactly('AnotherNamespace', 'ASecondNamespace', 'AThirdNamespace');

tests/Unit/Expressions/ForClasses/NotResideInTheseNamespacesTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,6 @@ public function test_it_should_return_false_if_reside_in_namespace(): void
4040
);
4141
}
4242

43-
public function test_it_should_deduplicate_namespaces(): void
44-
{
45-
$haveNameMatching = new NotResideInTheseNamespaces('MyNamespace', 'MyNamespace');
46-
47-
$classDesc = ClassDescription::getBuilder('MyNamespace\HappyIsland', 'src/Foo.php')->build();
48-
$because = 'we want to add this rule for our software';
49-
$violations = new Violations();
50-
$haveNameMatching->evaluate($classDesc, $violations, $because);
51-
52-
self::assertEquals(1, $violations->count());
53-
self::assertEquals(
54-
'should not reside in one of these namespaces: MyNamespace because '.$because,
55-
$haveNameMatching->describe($classDesc, $because)->toString()
56-
);
57-
}
58-
5943
public function test_it_should_check_multiple_namespaces_in_or(): void
6044
{
6145
$haveNameMatching = new NotResideInTheseNamespaces('AnotherNamespace', 'ASecondNamespace', 'AThirdNamespace');

0 commit comments

Comments
 (0)