Skip to content

Inverse the order of the parameters for NamespaceRegistry #592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public function createSymbolsConfiguration(array $config): SymbolsConfiguration
$exposeGlobalClasses,
$exposeGlobalFunctions,
NamespaceRegistry::create(
$excludedNamespaceRegexes,
$excludedNamespaceNames,
$excludedNamespaceRegexes,
),
null,
$legacyExposedSymbols,
Expand Down
20 changes: 10 additions & 10 deletions src/Symbol/NamespaceRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,39 @@ final class NamespaceRegistry
/**
* @var list<string>
*/
private array $namespaceRegexes;
private array $namespaceNames;

/**
* @var list<string>
*/
private array $namespaceNames;
private array $namespaceRegexes;

/**
* @param string[] $namespaceRegexes
* @param string[] $namespaceNames
* @param string[] $namespaceRegexes
*/
public static function create(
array $namespaceRegexes = [],
array $namespaceNames = []
array $namespaceNames = [],
array $namespaceRegexes = []
): self {
return new self(
array_unique($namespaceRegexes),
array_unique(
array_map('strtolower', $namespaceNames),
),
array_unique($namespaceRegexes),
);
}

/**
* @param list<string> $namespaceRegexes
* @param list<string> $namespaceNames
* @param list<string> $namespaceRegexes
*/
private function __construct(
array $namespaceRegexes,
array $namespaceNames
array $namespaceNames,
array $namespaceRegexes
) {
$this->namespaceRegexes = $namespaceRegexes;
$this->namespaceNames = $namespaceNames;
$this->namespaceRegexes = $namespaceRegexes;
}

public function belongsToRegisteredNamespace(string $symbolName): bool
Expand Down
1 change: 0 additions & 1 deletion tests/Configuration/ConfigurationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public function test_it_can_create_a_complete_configuration(): void
false,
false,
NamespaceRegistry::create(
[],
[
'PHPUnit\Runner',
'Bar',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public static function configProvider(): iterable
false,
false,
NamespaceRegistry::create(
[],
['PHPUnit\Runner'],
),
),
Expand All @@ -102,6 +101,7 @@ public static function configProvider(): iterable
false,
false,
NamespaceRegistry::create(
[],
['~^PHPUnit\\Runner(\\.*)?$~i'],
),
),
Expand Down Expand Up @@ -142,7 +142,6 @@ public static function configProvider(): iterable
false,
false,
NamespaceRegistry::create(
[],
[
'PHPUnit\Internal',
'PHPUnit\Runner',
Expand Down Expand Up @@ -170,13 +169,13 @@ public static function configProvider(): iterable
true,
true,
NamespaceRegistry::create(
[
'~^PHPUnit\\Runner(\\.*)?$~i',
],
[
'PHPUnit\Internal',
'PHPUnit\Runner',
],
[
'~^PHPUnit\\Runner(\\.*)?$~i',
],
),
null,
['acme\foo'],
Expand Down
2 changes: 0 additions & 2 deletions tests/Scoper/Symfony/XmlScoperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ public static function provideXmlFiles(): iterable
true,
true,
NamespaceRegistry::create(
[],
['Acme\Foo'],
),
),
Expand Down Expand Up @@ -567,7 +566,6 @@ public static function provideXmlFiles(): iterable
true,
true,
NamespaceRegistry::create(
[],
['Acme'],
),
),
Expand Down
6 changes: 0 additions & 6 deletions tests/Scoper/Symfony/YamlScoperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ public static function provideYamlFiles(): iterable
true,
true,
NamespaceRegistry::create(
[],
['Symfony\Component\Console'],
),
),
Expand Down Expand Up @@ -260,7 +259,6 @@ public static function provideYamlFiles(): iterable
true,
true,
NamespaceRegistry::create(
[],
['Acme\Controller'],
),
),
Expand Down Expand Up @@ -301,7 +299,6 @@ public static function provideYamlFiles(): iterable
true,
true,
NamespaceRegistry::create(
[],
['Acme\Foo'],
),
),
Expand Down Expand Up @@ -342,7 +339,6 @@ public static function provideYamlFiles(): iterable
true,
true,
NamespaceRegistry::create(
[],
['Acme\Foo'],
),
),
Expand Down Expand Up @@ -402,7 +398,6 @@ class: 'Acme\Bar\X'
true,
true,
NamespaceRegistry::create(
[],
['Acme\Foo'],
),
),
Expand Down Expand Up @@ -482,7 +477,6 @@ class: 'Humbug\Acme\Bar\X'
true,
true,
NamespaceRegistry::create(
[],
['Acme'],
),
),
Expand Down
14 changes: 7 additions & 7 deletions tests/Symbol/NamespaceRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ protected function setUp(): void
* @param string[] $namespaceNames
*/
public function test_it_can_tell_if_a_symbol_belongs_to_a_registered_namespace(
array $namespaceRegexes,
array $namespaceNames,
array $namespaceRegexes,
string $symbol,
bool $expected
): void
Expand All @@ -46,8 +46,8 @@ public function test_it_can_tell_if_a_symbol_belongs_to_a_registered_namespace(
$this->validateRegexes($namespaceRegexes);

$registeredNamespaces = NamespaceRegistry::create(
$namespaceRegexes,
$namespaceNames,
$namespaceRegexes,
);

$actual = $registeredNamespaces->belongsToRegisteredNamespace($symbol);
Expand All @@ -59,17 +59,17 @@ public static function provideNamespacedSymbol(): iterable
{
foreach (self::provideNamespaceNames() as $title => [$namespaceNames, $symbol, $expected]) {
yield '[name only] '.$title => [
[],
$namespaceNames,
[],
$symbol,
$expected,
];
}

foreach (self::provideNamespaceRegex() as $title => [$namespaceRegexes, $symbol, $expected]) {
yield '[regex only] '.$title => [
$namespaceRegexes,
[],
$namespaceRegexes,
$symbol,
$expected,
];
Expand Down Expand Up @@ -240,22 +240,22 @@ private static function provideNamespaceNameAndRegex(): iterable
];

yield 'matches the name but not the regex' => [
['/^Acme$/'],
['acme'],
['/^Acme$/'],
'acme\Foo',
true,
];

yield 'matches the regex but not the name' => [
['/^Acme$/'],
['ecma'],
['/^Acme$/'],
'Acme\Foo',
true,
];

yield 'matches both' => [
['/^Acme$/i'],
['Acme$'],
['/^Acme$/i'],
'Acme\Foo',
true,
];
Expand Down