From 4c3298440cee981a3085267405d67ca8b7180bdd Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 8 Dec 2025 00:46:07 +0100 Subject: [PATCH 1/2] [cleanup] Add unused public, remove unused methods and ignore rest --- composer.json | 1 + phpstan.neon | 22 ++++++++++++++- .../NodeAnalyzer/PhpAttributeAnalyzer.php | 24 ---------------- .../ValueObject/DataProviderNodes.php | 5 ---- .../Output/GitHubOutputFormatter.php | 5 +--- .../Output/GitlabOutputFormatter.php | 5 +--- .../Output/JUnitOutputFormatter.php | 2 +- src/NodeTypeResolver/Node/AttributeKey.php | 6 ---- src/Reflection/ReflectionResolver.php | 28 ------------------- 9 files changed, 25 insertions(+), 73 deletions(-) diff --git a/composer.json b/composer.json index 311704292d2..a3b34d60110 100644 --- a/composer.json +++ b/composer.json @@ -59,6 +59,7 @@ "symplify/phpstan-rules": "^14.9.3", "symplify/vendor-patches": "^11.5", "tomasvotruba/class-leak": "^2.1", + "tomasvotruba/unused-public": "^2.1", "tracy/tracy": "^2.11" }, "replace": { diff --git a/phpstan.neon b/phpstan.neon index 0a2f7a73fa0..c718ab070bf 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -14,7 +14,6 @@ parameters: # requires exact closure types checkMissingCallableSignature: true - treatPhpDocTypesAsCertain: false paths: @@ -47,6 +46,12 @@ parameters: narrow_param: true narrow_return: true + # see https://github.com/TomasVotruba/unused-public + unused_public: + methods: true + properties: true + constants: true + ignoreErrors: # required generics on interface array, not helpful - @@ -413,3 +418,18 @@ parameters: - identifier: method.parentMethodFinalByPhpDoc path: rules/TypeDeclaration/Rector/StmtsAwareInterface/DeclareStrictTypesRector.php + + # deprecated + - + identifier: public.method.unused + paths: + - rules/Transform/ValueObject/ClassMethodReference.php + - rules/CodeQuality/ValueObject/KeyAndExpr.php + + - + identifier: public.classConstant.unused + paths: + - rules/TypeDeclaration/Rector/StmtsAwareInterface/IncreaseDeclareStrictTypesRector.php + - rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php + - rules/Php81/Enum/AttributeName.php + diff --git a/rules/Php80/NodeAnalyzer/PhpAttributeAnalyzer.php b/rules/Php80/NodeAnalyzer/PhpAttributeAnalyzer.php index 7143d49b9de..b65176e076e 100644 --- a/rules/Php80/NodeAnalyzer/PhpAttributeAnalyzer.php +++ b/rules/Php80/NodeAnalyzer/PhpAttributeAnalyzer.php @@ -23,7 +23,6 @@ { public function __construct( private NodeNameResolver $nodeNameResolver, - private ReflectionProvider $reflectionProvider, ) { } @@ -42,29 +41,6 @@ public function hasPhpAttribute(Property | ClassLike | ClassMethod | Param $node return false; } - /** - * @param AttributeName::* $attributeClass - */ - public function hasInheritedPhpAttribute(Class_ $class, string $attributeClass): bool - { - $className = (string) $this->nodeNameResolver->getName($class); - if (! $this->reflectionProvider->hasClass($className)) { - return false; - } - - $classReflection = $this->reflectionProvider->getClass($className); - $ancestorClassReflections = [...$classReflection->getParents(), ...$classReflection->getInterfaces()]; - - foreach ($ancestorClassReflections as $ancestorClassReflection) { - $nativeReflection = $ancestorClassReflection->getNativeReflection(); - if ($nativeReflection->getAttributes($attributeClass) !== []) { - return true; - } - } - - return false; - } - /** * @param string[] $attributeClasses */ diff --git a/rules/TypeDeclaration/ValueObject/DataProviderNodes.php b/rules/TypeDeclaration/ValueObject/DataProviderNodes.php index e6bba080c7a..a3f59ea58d5 100644 --- a/rules/TypeDeclaration/ValueObject/DataProviderNodes.php +++ b/rules/TypeDeclaration/ValueObject/DataProviderNodes.php @@ -34,11 +34,6 @@ public function __construct( Assert::allIsInstanceOf($phpDocTagNodes, PhpDocTagNode::class); } - public function isEmpty(): bool - { - return $this->getClassMethods() === []; - } - /** * @return ClassMethod[] */ diff --git a/src/ChangesReporting/Output/GitHubOutputFormatter.php b/src/ChangesReporting/Output/GitHubOutputFormatter.php index b7c266b48d6..0c78cc11252 100644 --- a/src/ChangesReporting/Output/GitHubOutputFormatter.php +++ b/src/ChangesReporting/Output/GitHubOutputFormatter.php @@ -23,10 +23,7 @@ */ final readonly class GitHubOutputFormatter implements OutputFormatterInterface { - /** - * @var string - */ - public const NAME = 'github'; + private const NAME = 'github'; private const GROUP_NAME = 'Rector report'; diff --git a/src/ChangesReporting/Output/GitlabOutputFormatter.php b/src/ChangesReporting/Output/GitlabOutputFormatter.php index 14c8e6d9075..7911570bd3b 100644 --- a/src/ChangesReporting/Output/GitlabOutputFormatter.php +++ b/src/ChangesReporting/Output/GitlabOutputFormatter.php @@ -17,10 +17,7 @@ final readonly class GitlabOutputFormatter implements OutputFormatterInterface { - /** - * @var string - */ - public const NAME = 'gitlab'; + private const NAME = 'gitlab'; private const ERROR_TYPE_ISSUE = 'issue'; diff --git a/src/ChangesReporting/Output/JUnitOutputFormatter.php b/src/ChangesReporting/Output/JUnitOutputFormatter.php index 978295b7513..1b881c2a3bc 100644 --- a/src/ChangesReporting/Output/JUnitOutputFormatter.php +++ b/src/ChangesReporting/Output/JUnitOutputFormatter.php @@ -18,7 +18,7 @@ final readonly class JUnitOutputFormatter implements OutputFormatterInterface { - public const NAME = 'junit'; + private const NAME = 'junit'; private const XML_ATTRIBUTE_FILE = 'file'; diff --git a/src/NodeTypeResolver/Node/AttributeKey.php b/src/NodeTypeResolver/Node/AttributeKey.php index 10ca311bff9..c65ee8824f3 100644 --- a/src/NodeTypeResolver/Node/AttributeKey.php +++ b/src/NodeTypeResolver/Node/AttributeKey.php @@ -261,12 +261,6 @@ final class AttributeKey */ public const IS_USED_AS_ARG_BY_REF_VALUE = 'is_used_as_arg_by_ref_value'; - /** - * @deprecated as never used - * @var string - */ - public const ATTRIBUTE_COMMENT = 'attribute_comment'; - /** * @var string */ diff --git a/src/Reflection/ReflectionResolver.php b/src/Reflection/ReflectionResolver.php index 04f47384b53..2414451ce63 100644 --- a/src/Reflection/ReflectionResolver.php +++ b/src/Reflection/ReflectionResolver.php @@ -216,34 +216,6 @@ public function resolveFunctionLikeReflectionFromCall( return null; } - public function resolveMethodReflectionFromClassMethod(ClassMethod $classMethod, Scope $scope): ?MethodReflection - { - $classReflection = $scope->getClassReflection(); - if (! $classReflection instanceof ClassReflection) { - return null; - } - - $className = $classReflection->getName(); - $methodName = $this->nodeNameResolver->getName($classMethod); - - return $this->resolveMethodReflection($className, $methodName, $scope); - } - - public function resolveFunctionReflectionFromFunction(Function_ $function): ?FunctionReflection - { - $name = $this->nodeNameResolver->getName($function); - if ($name === null) { - return null; - } - - $functionName = new Name($name); - if ($this->reflectionProvider->hasFunction($functionName, null)) { - return $this->reflectionProvider->getFunction($functionName, null); - } - - return null; - } - public function resolveMethodReflectionFromNew(New_ $new): ?MethodReflection { $newClassType = $this->nodeTypeResolver->getType($new->class); From f0da398e9dde0b83516fdd8c254ea876890a60b4 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 7 Dec 2025 23:48:43 +0000 Subject: [PATCH 2/2] [ci-review] Rector Rectify --- rules/Php80/NodeAnalyzer/PhpAttributeAnalyzer.php | 3 --- src/Reflection/ReflectionResolver.php | 2 -- 2 files changed, 5 deletions(-) diff --git a/rules/Php80/NodeAnalyzer/PhpAttributeAnalyzer.php b/rules/Php80/NodeAnalyzer/PhpAttributeAnalyzer.php index b65176e076e..b76e243b90b 100644 --- a/rules/Php80/NodeAnalyzer/PhpAttributeAnalyzer.php +++ b/rules/Php80/NodeAnalyzer/PhpAttributeAnalyzer.php @@ -10,13 +10,10 @@ use PhpParser\Node\Expr\Array_; use PhpParser\Node\Param; use PhpParser\Node\Scalar\String_; -use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Property; -use PHPStan\Reflection\ReflectionProvider; use Rector\NodeNameResolver\NodeNameResolver; -use Rector\Php81\Enum\AttributeName; use Rector\PhpAttribute\Enum\DocTagNodeState; final readonly class PhpAttributeAnalyzer diff --git a/src/Reflection/ReflectionResolver.php b/src/Reflection/ReflectionResolver.php index 2414451ce63..2ff0ca16f5c 100644 --- a/src/Reflection/ReflectionResolver.php +++ b/src/Reflection/ReflectionResolver.php @@ -17,8 +17,6 @@ use PhpParser\Node\Name; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassLike; -use PhpParser\Node\Stmt\ClassMethod; -use PhpParser\Node\Stmt\Function_; use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\FunctionReflection;