diff --git a/packages/NetteTesterToPHPUnit/src/Rector/Class_/NetteTesterClassToPHPUnitClassRector.php b/packages/NetteTesterToPHPUnit/src/Rector/Class_/NetteTesterClassToPHPUnitClassRector.php index 46e69a9ed985..1eb445dccd46 100644 --- a/packages/NetteTesterToPHPUnit/src/Rector/Class_/NetteTesterClassToPHPUnitClassRector.php +++ b/packages/NetteTesterToPHPUnit/src/Rector/Class_/NetteTesterClassToPHPUnitClassRector.php @@ -135,7 +135,7 @@ private function processMethods(Class_ $class): void $methods = $this->classManipulator->getMethods($class); foreach ($methods as $method) { - if ($this->isNamesInsensitive($method, ['setUp', 'tearDown'])) { + if ($this->isNames($method, ['setUp', 'tearDown'])) { $this->makeProtected($method); } } diff --git a/packages/NetteToSymfony/src/Route/RouteInfoFactory.php b/packages/NetteToSymfony/src/Route/RouteInfoFactory.php index 45f718ffc6a1..970ae69b1cd4 100644 --- a/packages/NetteToSymfony/src/Route/RouteInfoFactory.php +++ b/packages/NetteToSymfony/src/Route/RouteInfoFactory.php @@ -55,7 +55,7 @@ public function createFromNode(Node $node): ?RouteInfo return null; } - $method = $this->nameResolver->matchNameInsensitiveInMap($node, [ + $method = $this->nameResolver->matchNameInMap($node, [ 'get' => 'GET', 'head' => 'HEAD', 'post' => 'POST', diff --git a/packages/PHPUnit/src/Rector/MethodCall/UseSpecificWillMethodRector.php b/packages/PHPUnit/src/Rector/MethodCall/UseSpecificWillMethodRector.php index 1ea348543b7f..9546e8bd470d 100644 --- a/packages/PHPUnit/src/Rector/MethodCall/UseSpecificWillMethodRector.php +++ b/packages/PHPUnit/src/Rector/MethodCall/UseSpecificWillMethodRector.php @@ -84,11 +84,11 @@ public function refactor(Node $node): ?Node return null; } - if ($this->isNameInsensitive($node, 'with')) { + if ($this->isName($node, 'with')) { return $this->processWithCall($node); } - if ($this->isNameInsensitive($node, 'will')) { + if ($this->isName($node, 'will')) { return $this->processWillCall($node); } @@ -123,7 +123,7 @@ private function processWillCall(Node $node): ?Node $nestedMethodCall = $node->args[0]->value; foreach ($this->nestedMethodToRenameMap as $oldMethodName => $newParentMethodName) { - if ($this->isNameInsensitive($nestedMethodCall, $oldMethodName)) { + if ($this->isName($nestedMethodCall, $oldMethodName)) { $node->name = new Identifier($newParentMethodName); // move args up diff --git a/packages/Php/src/Rector/ConstFetch/RenameConstantRector.php b/packages/Php/src/Rector/ConstFetch/RenameConstantRector.php index 2819a5189b28..659fc03bf05f 100644 --- a/packages/Php/src/Rector/ConstFetch/RenameConstantRector.php +++ b/packages/Php/src/Rector/ConstFetch/RenameConstantRector.php @@ -65,7 +65,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { foreach ($this->oldToNewConstants as $oldConstant => $newConstant) { - if (! $this->isNameInsensitive($node, $oldConstant)) { + if (! $this->isName($node, $oldConstant)) { continue; } diff --git a/packages/Php/src/Rector/FunctionLike/Php4ConstructorRector.php b/packages/Php/src/Rector/FunctionLike/Php4ConstructorRector.php index c65b31627bd8..0a79682cdc7e 100644 --- a/packages/Php/src/Rector/FunctionLike/Php4ConstructorRector.php +++ b/packages/Php/src/Rector/FunctionLike/Php4ConstructorRector.php @@ -86,7 +86,7 @@ public function refactor(Node $node): ?Node $this->processClassMethodStatementsForParentConstructorCalls($node); // not PSR-4 constructor - if (! $this->isNameInsensitive($classNode, $this->getName($node))) { + if (! $this->isName($classNode, $this->getName($node))) { return null; } @@ -193,7 +193,7 @@ private function processParentPhp4ConstructCall(Node $node): void } // it's not a parent PHP 4 constructor call - if (! $this->isNameInsensitive($node, $parentClassName)) { + if (! $this->isName($node, $parentClassName)) { return; } diff --git a/src/PhpParser/Node/Resolver/NameResolver.php b/src/PhpParser/Node/Resolver/NameResolver.php index 79204797ebec..94c6d15b8a2d 100644 --- a/src/PhpParser/Node/Resolver/NameResolver.php +++ b/src/PhpParser/Node/Resolver/NameResolver.php @@ -100,10 +100,10 @@ function (ClassConstFetch $classConstFetch): ?string { /** * @param string[] $map */ - public function matchNameInsensitiveInMap(Node $node, array $map): ?string + public function matchNameInMap(Node $node, array $map): ?string { foreach ($map as $nameToMatch => $return) { - if ($this->isNameInsensitive($node, $nameToMatch)) { + if ($this->isName($node, $nameToMatch)) { return $return; } } @@ -111,18 +111,13 @@ public function matchNameInsensitiveInMap(Node $node, array $map): ?string return null; } - public function isNameInsensitive(Node $node, string $name): bool - { - return strtolower((string) $this->getName($node)) === strtolower($name); - } - /** * @param string[] $names */ - public function isNamesInsensitive(Node $node, array $names): bool + public function isNames(Node $node, array $names): bool { foreach ($names as $name) { - if ($this->isNameInsensitive($node, $name)) { + if ($this->isName($node, $name)) { return true; } } @@ -151,15 +146,12 @@ public function isName(Node $node, string $name): bool return fnmatch($name, $resolvedName, FNM_NOESCAPE); } - return $resolvedName === $name; - } + // special case + if ($name === 'Object') { + return $name === $resolvedName; + } - /** - * @param string[] $names - */ - public function isNames(Node $node, array $names): bool - { - return in_array($this->getName($node), $names, true); + return strtolower($resolvedName) === strtolower($name); } public function getName(Node $node): ?string diff --git a/src/Rector/AbstractPHPUnitRector.php b/src/Rector/AbstractPHPUnitRector.php index a754e3375954..3ef2fa6a1372 100644 --- a/src/Rector/AbstractPHPUnitRector.php +++ b/src/Rector/AbstractPHPUnitRector.php @@ -15,7 +15,7 @@ protected function isPHPUnitMethodName(Node $node, string $name): bool return false; } - return $this->isNameInsensitive($node, $name); + return $this->isName($node, $name); } /** @@ -27,7 +27,7 @@ protected function isPHPUnitMethodNames(Node $node, array $names): bool return false; } - return $this->isNamesInsensitive($node, $names); + return $this->isNames($node, $names); } protected function isInTestClass(Node $node): bool diff --git a/src/Rector/AbstractRector/NameResolverTrait.php b/src/Rector/AbstractRector/NameResolverTrait.php index cb4d4e9c30c6..7f07c7aec21f 100644 --- a/src/Rector/AbstractRector/NameResolverTrait.php +++ b/src/Rector/AbstractRector/NameResolverTrait.php @@ -34,31 +34,12 @@ public function areNamesEqual(Node $firstNode, Node $secondNode): bool return $this->nameResolver->areNamesEqual($firstNode, $secondNode); } - public function isNameInsensitive(Node $node, string $name): bool - { - return $this->nameResolver->isNameInsensitive($node, $name); - } - - /** - * @param string[] $names - */ - public function isNamesInsensitive(Node $node, array $names): bool - { - return $this->nameResolver->isNamesInsensitive($node, $names); - } - /** * @param string[] $names */ public function isNames(Node $node, array $names): bool { - foreach ($names as $name) { - if ($this->isName($node, $name)) { - return true; - } - } - - return false; + return $this->nameResolver->isNames($node, $names); } public function getName(Node $node): ?string diff --git a/src/Rector/Constant/RenameClassConstantRector.php b/src/Rector/Constant/RenameClassConstantRector.php index 30050c84f3f9..4f6575370f06 100644 --- a/src/Rector/Constant/RenameClassConstantRector.php +++ b/src/Rector/Constant/RenameClassConstantRector.php @@ -73,7 +73,7 @@ public function refactor(Node $node): ?Node } foreach ($oldToNewConstants as $oldConstant => $newConstant) { - if (! $this->isNameInsensitive($node->name, $oldConstant)) { + if (! $this->isName($node->name, $oldConstant)) { continue; } diff --git a/src/Rector/Function_/RenameFunctionRector.php b/src/Rector/Function_/RenameFunctionRector.php index b9f32fb5f9db..10a53ac14338 100644 --- a/src/Rector/Function_/RenameFunctionRector.php +++ b/src/Rector/Function_/RenameFunctionRector.php @@ -54,7 +54,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { foreach ($this->oldFunctionToNewFunction as $oldFunction => $newFunction) { - if (! $this->isNameInsensitive($node, $oldFunction)) { + if (! $this->isName($node, $oldFunction)) { continue; } diff --git a/src/Rector/MethodCall/RenameMethodCallRector.php b/src/Rector/MethodCall/RenameMethodCallRector.php index da6ed4f0cf47..b0c0725ca09e 100644 --- a/src/Rector/MethodCall/RenameMethodCallRector.php +++ b/src/Rector/MethodCall/RenameMethodCallRector.php @@ -72,7 +72,7 @@ public function refactor(Node $node): ?Node } foreach ($oldToNewMethods as $oldMethod => $newMethod) { - if (! $this->isNameInsensitive($node, $oldMethod)) { + if (! $this->isName($node, $oldMethod)) { continue; } diff --git a/src/Rector/MethodCall/RenameMethodRector.php b/src/Rector/MethodCall/RenameMethodRector.php index fc02db9f9656..0a1d08a0620f 100644 --- a/src/Rector/MethodCall/RenameMethodRector.php +++ b/src/Rector/MethodCall/RenameMethodRector.php @@ -74,7 +74,7 @@ public function refactor(Node $node): ?Node } foreach ($oldToNewMethods as $oldMethod => $newMethod) { - if (! $this->isNameInsensitive($node, $oldMethod)) { + if (! $this->isName($node, $oldMethod)) { continue; } diff --git a/src/Rector/MethodCall/RenameStaticMethodRector.php b/src/Rector/MethodCall/RenameStaticMethodRector.php index 8eacc2024ad0..613f5555e87d 100644 --- a/src/Rector/MethodCall/RenameStaticMethodRector.php +++ b/src/Rector/MethodCall/RenameStaticMethodRector.php @@ -70,7 +70,7 @@ public function refactor(Node $node): ?Node } foreach ($oldToNewMethods as $oldMethod => $newMethod) { - if (! $this->isNameInsensitive($node, $oldMethod)) { + if (! $this->isName($node, $oldMethod)) { continue; } diff --git a/src/Rector/Property/RenamePropertyRector.php b/src/Rector/Property/RenamePropertyRector.php index 8e166b4ca471..e621cf469fa0 100644 --- a/src/Rector/Property/RenamePropertyRector.php +++ b/src/Rector/Property/RenamePropertyRector.php @@ -64,7 +64,7 @@ public function refactor(Node $node): ?Node } foreach ($oldToNewProperties as $oldProperty => $newProperty) { - if (! $this->isNameInsensitive($node, $oldProperty)) { + if (! $this->isName($node, $oldProperty)) { continue; }