From 5f21af7a492f8be43972c1d89fa150ae9e37475c Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 27 Dec 2024 20:20:25 +0700 Subject: [PATCH] Remove unused AssignVariableNameResolverInterface instances (#6631) --- .../NewAssignVariableNameResolver.php | 40 ------ ...ropertyFetchAssignVariableNameResolver.php | 49 ------- .../AssignVariableNameResolverInterface.php | 20 --- rules/Naming/Naming/VariableNaming.php | 120 ------------------ 4 files changed, 229 deletions(-) delete mode 100644 rules/Naming/AssignVariableNameResolver/NewAssignVariableNameResolver.php delete mode 100644 rules/Naming/AssignVariableNameResolver/PropertyFetchAssignVariableNameResolver.php delete mode 100644 rules/Naming/Contract/AssignVariableNameResolverInterface.php diff --git a/rules/Naming/AssignVariableNameResolver/NewAssignVariableNameResolver.php b/rules/Naming/AssignVariableNameResolver/NewAssignVariableNameResolver.php deleted file mode 100644 index 1279f3397c9..00000000000 --- a/rules/Naming/AssignVariableNameResolver/NewAssignVariableNameResolver.php +++ /dev/null @@ -1,40 +0,0 @@ - - */ -final readonly class NewAssignVariableNameResolver implements AssignVariableNameResolverInterface -{ - public function __construct( - private NodeNameResolver $nodeNameResolver - ) { - } - - public function match(Node $node): bool - { - return $node instanceof New_; - } - - /** - * @param New_ $node - */ - public function resolve(Node $node): string - { - $className = $this->nodeNameResolver->getName($node->class); - if ($className === null) { - throw new NotImplementedYetException(); - } - - return $this->nodeNameResolver->getShortName($className); - } -} diff --git a/rules/Naming/AssignVariableNameResolver/PropertyFetchAssignVariableNameResolver.php b/rules/Naming/AssignVariableNameResolver/PropertyFetchAssignVariableNameResolver.php deleted file mode 100644 index a09f977dcf5..00000000000 --- a/rules/Naming/AssignVariableNameResolver/PropertyFetchAssignVariableNameResolver.php +++ /dev/null @@ -1,49 +0,0 @@ - - */ -final readonly class PropertyFetchAssignVariableNameResolver implements AssignVariableNameResolverInterface -{ - public function __construct( - private NodeNameResolver $nodeNameResolver - ) { - } - - public function match(Node $node): bool - { - return $node instanceof PropertyFetch; - } - - /** - * @param PropertyFetch $node - */ - public function resolve(Node $node): string - { - $varName = $this->nodeNameResolver->getName($node->var); - if (! is_string($varName)) { - throw new NotImplementedYetException(); - } - - $propertyName = $this->nodeNameResolver->getName($node->name); - if (! is_string($propertyName)) { - throw new NotImplementedYetException(); - } - - if ($varName === 'this') { - return $propertyName; - } - - return $varName . ucfirst($propertyName); - } -} diff --git a/rules/Naming/Contract/AssignVariableNameResolverInterface.php b/rules/Naming/Contract/AssignVariableNameResolverInterface.php deleted file mode 100644 index bc96ce8bd8d..00000000000 --- a/rules/Naming/Contract/AssignVariableNameResolverInterface.php +++ /dev/null @@ -1,20 +0,0 @@ -assignVariableNameResolvers = [ - $propertyFetchAssignVariableNameResolver, - $newAssignVariableNameResolver, - ]; - } - /** * @api used in downgrade */ @@ -68,91 +35,4 @@ public function createCountedValueName(string $valueName, ?Scope $scope): string return $valueName; } - - private function resolveFromNodeAndType(Node $node, Type $type): ?string - { - $variableName = $this->resolveBareFromNode($node); - if ($variableName === null) { - return null; - } - - // adjust static to specific class - if ($variableName === 'this' && $type instanceof ThisType) { - $shortClassName = $this->nodeNameResolver->getShortName($type->getClassName()); - return lcfirst($shortClassName); - } - - return $this->nodeNameResolver->getShortName($variableName); - } - - private function resolveFromNode(Node $node): ?string - { - $nodeType = $this->nodeTypeResolver->getType($node); - return $this->resolveFromNodeAndType($node, $nodeType); - } - - private function resolveBareFromNode(Node $node): ?string - { - $unwrappedNode = $this->unwrapNode($node); - - if (! $unwrappedNode instanceof Node) { - return null; - } - - foreach ($this->assignVariableNameResolvers as $assignVariableNameResolver) { - if ($assignVariableNameResolver->match($unwrappedNode)) { - return $assignVariableNameResolver->resolve($unwrappedNode); - } - } - - if ($unwrappedNode instanceof MethodCall || $unwrappedNode instanceof NullsafeMethodCall || $unwrappedNode instanceof StaticCall) { - return $this->resolveFromMethodCall($unwrappedNode); - } - - if ($unwrappedNode instanceof FuncCall) { - return $this->resolveFromNode($unwrappedNode->name); - } - - $paramName = $this->nodeNameResolver->getName($unwrappedNode); - if ($paramName !== null) { - return $paramName; - } - - if ($unwrappedNode instanceof String_) { - return $unwrappedNode->value; - } - - return null; - } - - private function resolveFromMethodCall(MethodCall | NullsafeMethodCall | StaticCall $node): ?string - { - if ($node->name instanceof MethodCall) { - return $this->resolveFromMethodCall($node->name); - } - - $methodName = $this->nodeNameResolver->getName($node->name); - if (! is_string($methodName)) { - return null; - } - - return $methodName; - } - - private function unwrapNode(Node $node): ?Node - { - if ($node instanceof Arg) { - return $node->value; - } - - if ($node instanceof Cast) { - return $node->expr; - } - - if ($node instanceof Ternary) { - return $node->if; - } - - return $node; - } }