Skip to content
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 @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/NetteToSymfony/src/Route/RouteInfoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
26 changes: 9 additions & 17 deletions src/PhpParser/Node/Resolver/NameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,24 @@ 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;
}
}

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;
}
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Rector/AbstractPHPUnitRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected function isPHPUnitMethodName(Node $node, string $name): bool
return false;
}

return $this->isNameInsensitive($node, $name);
return $this->isName($node, $name);
}

/**
Expand All @@ -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
Expand Down
21 changes: 1 addition & 20 deletions src/Rector/AbstractRector/NameResolverTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Rector/Constant/RenameClassConstantRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rector/Function_/RenameFunctionRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rector/MethodCall/RenameMethodCallRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rector/MethodCall/RenameMethodRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rector/MethodCall/RenameStaticMethodRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rector/Property/RenamePropertyRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down