diff --git a/rector.php b/rector.php index 9c7d49dbe20..eb192f99f2d 100644 --- a/rector.php +++ b/rector.php @@ -68,9 +68,6 @@ $parameters->set(Option::AUTO_IMPORT_NAMES, true); $parameters->set(Option::SKIP, [ - // possibly leave that to PHPStan rule, already covered - \Rector\CodeQuality\Rector\Name\FixClassCaseSensitivityNameRector::class, - StringClassNameToClassConstantRector::class, // some classes in config might not exist without dev dependencies SplitStringClassConstantToClassConstFetchRector::class, diff --git a/rules/CodeQuality/Rector/Name/FixClassCaseSensitivityNameRector.php b/rules/CodeQuality/Rector/Name/FixClassCaseSensitivityNameRector.php deleted file mode 100644 index e75fe7066cb..00000000000 --- a/rules/CodeQuality/Rector/Name/FixClassCaseSensitivityNameRector.php +++ /dev/null @@ -1,208 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [Name::class]; - } - - /** - * @param Name $node - */ - public function refactor(Node $node): ?Node - { - $fullyQualifiedName = $this->resolveFullyQualifiedName($node); - if ($fullyQualifiedName === null) { - return null; - } - - if (! $this->reflectionProvider->hasClass($fullyQualifiedName)) { - return null; - } - - $classReflection = $this->reflectionProvider->getClass($fullyQualifiedName); - if ($classReflection->isBuiltin()) { - // skip built-in classes - return null; - } - - $realClassName = $classReflection->getName(); - if (strtolower($realClassName) !== strtolower($fullyQualifiedName)) { - // skip class alias - return null; - } - - if ($realClassName === $fullyQualifiedName) { - return null; - } - - $scope = $node->getAttribute(AttributeKey::SCOPE); - $hasFunction = $this->reflectionProvider->hasFunction(new FullyQualified($fullyQualifiedName), $scope); - if ($hasFunction) { - return null; - } - - $parent = $node->getAttribute(AttributeKey::PARENT_NODE); - - // do not FQN use imports - if ($parent instanceof UseUse) { - return new Name($realClassName); - } - - return new FullyQualified($realClassName); - } - - private function resolveFullyQualifiedName(Name $name): string|null - { - $parent = $name->getAttribute(AttributeKey::PARENT_NODE); - if (! $parent instanceof Node) { - return null; - } - - $originalName = $name->getAttribute(AttributeKey::ORIGINAL_NAME); - if (! $originalName instanceof Name) { - // unable to resolve - return null; - } - - if ($this->isParamTypeNameOrClassConstFetchClassName($parent)) { - return $this->processParamTypeNameOrClassConstFetchClassName($name, $originalName); - } - - if ($parent instanceof UnionType) { - return $this->processUnionType($parent, $name, $originalName); - } - - // replace parts from the old one - $originalReversedParts = array_reverse($originalName->parts); - $resolvedReversedParts = array_reverse($name->parts); - - $mergedReversedParts = $originalReversedParts + $resolvedReversedParts; - $mergedParts = array_reverse($mergedReversedParts); - - return implode('\\', $mergedParts); - } - - private function isParamTypeNameOrClassConstFetchClassName(Node $node): bool - { - if (! $node instanceof Param && ! $node instanceof ClassConstFetch) { - return false; - } - - if ($node instanceof Param) { - return $node->type instanceof Name; - } - - return $node->class instanceof Name; - } - - private function processUnionType(UnionType $unionType, Name $name, Name $originalName): string - { - foreach ($unionType->types as $type) { - if (! $type instanceof Name) { - continue; - } - - if ($type !== $name) { - continue; - } - - return $this->processParamTypeNameOrClassConstFetchClassName($name, $originalName); - } - - return ''; - } - - private function processParamTypeNameOrClassConstFetchClassName(Name $name, Name $originalName): string - { - $oldTokens = $this->file->getOldTokens(); - $startTokenPos = $name->getStartTokenPos(); - - if (! isset($oldTokens[$startTokenPos][1])) { - return ''; - } - - $type = $oldTokens[$startTokenPos][1]; - if (str_contains($type, '\\')) { - return ''; - } - - $last = $originalName->getLast(); - if (strtolower($last) !== strtolower($type)) { - return ''; - } - - $name->parts[count($name->parts) - 1] = $type; - return (string) $name; - } -} diff --git a/rules/DeadCode/NodeAnalyzer/ExprUsedInNextNodeAnalyzer.php b/rules/DeadCode/NodeAnalyzer/ExprUsedInNextNodeAnalyzer.php index 83acc07db10..db3d703c7f9 100644 --- a/rules/DeadCode/NodeAnalyzer/ExprUsedInNextNodeAnalyzer.php +++ b/rules/DeadCode/NodeAnalyzer/ExprUsedInNextNodeAnalyzer.php @@ -20,9 +20,7 @@ public function isUsed(Expr $expr): bool { return (bool) $this->betterNodeFinder->findFirstNext( $expr, - function (Node $node) use ($expr): bool { - return $this->exprUsedInNodeAnalyzer->isUsed($node, $expr); - } + fn (Node $node): bool => $this->exprUsedInNodeAnalyzer->isUsed($node, $expr) ); } } diff --git a/rules/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector.php b/rules/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector.php index 1fa7f1f85d3..502144c4bf9 100644 --- a/rules/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector.php +++ b/rules/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector.php @@ -57,10 +57,6 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { -// if ($this->isInAnonymousClass($node)) { -// return null; -// } - if ($this->shouldSkipProperty($node)) { return null; } diff --git a/tests/Issues/Issue6675/Fixture/fixture.php.inc b/tests/Issues/Issue6675/Fixture/fixture.php.inc index 907178466fd..9e69ec61f57 100644 --- a/tests/Issues/Issue6675/Fixture/fixture.php.inc +++ b/tests/Issues/Issue6675/Fixture/fixture.php.inc @@ -12,6 +12,6 @@ echo mysql_error(); namespace Rector\Core\Tests\Issues\Issue6675\Fixture; $db = mysqli_connect("server","user","password"); -echo mysqli_error($db); +echo mysql_error(); ?>