Skip to content

Commit 6efa094

Browse files
[cleanup] Add unused public, remove unused methods and ignore rest (#7733)
* [cleanup] Add unused public, remove unused methods and ignore rest * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <actions@github.com>
1 parent f5c7bbd commit 6efa094

File tree

9 files changed

+25
-78
lines changed

9 files changed

+25
-78
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"symplify/phpstan-rules": "^14.9.3",
6060
"symplify/vendor-patches": "^11.5",
6161
"tomasvotruba/class-leak": "^2.1",
62+
"tomasvotruba/unused-public": "^2.1",
6263
"tracy/tracy": "^2.11"
6364
},
6465
"replace": {

phpstan.neon

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ parameters:
1414

1515
# requires exact closure types
1616
checkMissingCallableSignature: true
17-
1817
treatPhpDocTypesAsCertain: false
1918

2019
paths:
@@ -47,6 +46,12 @@ parameters:
4746
narrow_param: true
4847
narrow_return: true
4948

49+
# see https://github.com/TomasVotruba/unused-public
50+
unused_public:
51+
methods: true
52+
properties: true
53+
constants: true
54+
5055
ignoreErrors:
5156
# required generics on interface array, not helpful
5257
-
@@ -413,3 +418,18 @@ parameters:
413418
-
414419
identifier: method.parentMethodFinalByPhpDoc
415420
path: rules/TypeDeclaration/Rector/StmtsAwareInterface/DeclareStrictTypesRector.php
421+
422+
# deprecated
423+
-
424+
identifier: public.method.unused
425+
paths:
426+
- rules/Transform/ValueObject/ClassMethodReference.php
427+
- rules/CodeQuality/ValueObject/KeyAndExpr.php
428+
429+
-
430+
identifier: public.classConstant.unused
431+
paths:
432+
- rules/TypeDeclaration/Rector/StmtsAwareInterface/IncreaseDeclareStrictTypesRector.php
433+
- rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php
434+
- rules/Php81/Enum/AttributeName.php
435+

rules/Php80/NodeAnalyzer/PhpAttributeAnalyzer.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,16 @@
1010
use PhpParser\Node\Expr\Array_;
1111
use PhpParser\Node\Param;
1212
use PhpParser\Node\Scalar\String_;
13-
use PhpParser\Node\Stmt\Class_;
1413
use PhpParser\Node\Stmt\ClassLike;
1514
use PhpParser\Node\Stmt\ClassMethod;
1615
use PhpParser\Node\Stmt\Property;
17-
use PHPStan\Reflection\ReflectionProvider;
1816
use Rector\NodeNameResolver\NodeNameResolver;
19-
use Rector\Php81\Enum\AttributeName;
2017
use Rector\PhpAttribute\Enum\DocTagNodeState;
2118

2219
final readonly class PhpAttributeAnalyzer
2320
{
2421
public function __construct(
2522
private NodeNameResolver $nodeNameResolver,
26-
private ReflectionProvider $reflectionProvider,
2723
) {
2824
}
2925

@@ -42,29 +38,6 @@ public function hasPhpAttribute(Property | ClassLike | ClassMethod | Param $node
4238
return false;
4339
}
4440

45-
/**
46-
* @param AttributeName::* $attributeClass
47-
*/
48-
public function hasInheritedPhpAttribute(Class_ $class, string $attributeClass): bool
49-
{
50-
$className = (string) $this->nodeNameResolver->getName($class);
51-
if (! $this->reflectionProvider->hasClass($className)) {
52-
return false;
53-
}
54-
55-
$classReflection = $this->reflectionProvider->getClass($className);
56-
$ancestorClassReflections = [...$classReflection->getParents(), ...$classReflection->getInterfaces()];
57-
58-
foreach ($ancestorClassReflections as $ancestorClassReflection) {
59-
$nativeReflection = $ancestorClassReflection->getNativeReflection();
60-
if ($nativeReflection->getAttributes($attributeClass) !== []) {
61-
return true;
62-
}
63-
}
64-
65-
return false;
66-
}
67-
6841
/**
6942
* @param string[] $attributeClasses
7043
*/

rules/TypeDeclaration/ValueObject/DataProviderNodes.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ public function __construct(
3434
Assert::allIsInstanceOf($phpDocTagNodes, PhpDocTagNode::class);
3535
}
3636

37-
public function isEmpty(): bool
38-
{
39-
return $this->getClassMethods() === [];
40-
}
41-
4237
/**
4338
* @return ClassMethod[]
4439
*/

src/ChangesReporting/Output/GitHubOutputFormatter.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
*/
2424
final readonly class GitHubOutputFormatter implements OutputFormatterInterface
2525
{
26-
/**
27-
* @var string
28-
*/
29-
public const NAME = 'github';
26+
private const NAME = 'github';
3027

3128
private const GROUP_NAME = 'Rector report';
3229

src/ChangesReporting/Output/GitlabOutputFormatter.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717

1818
final readonly class GitlabOutputFormatter implements OutputFormatterInterface
1919
{
20-
/**
21-
* @var string
22-
*/
23-
public const NAME = 'gitlab';
20+
private const NAME = 'gitlab';
2421

2522
private const ERROR_TYPE_ISSUE = 'issue';
2623

src/ChangesReporting/Output/JUnitOutputFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
final readonly class JUnitOutputFormatter implements OutputFormatterInterface
2020
{
21-
public const NAME = 'junit';
21+
private const NAME = 'junit';
2222

2323
private const XML_ATTRIBUTE_FILE = 'file';
2424

src/NodeTypeResolver/Node/AttributeKey.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,6 @@ final class AttributeKey
261261
*/
262262
public const IS_USED_AS_ARG_BY_REF_VALUE = 'is_used_as_arg_by_ref_value';
263263

264-
/**
265-
* @deprecated as never used
266-
* @var string
267-
*/
268-
public const ATTRIBUTE_COMMENT = 'attribute_comment';
269-
270264
/**
271265
* @var string
272266
*/

src/Reflection/ReflectionResolver.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
use PhpParser\Node\Name;
1818
use PhpParser\Node\Stmt\Class_;
1919
use PhpParser\Node\Stmt\ClassLike;
20-
use PhpParser\Node\Stmt\ClassMethod;
21-
use PhpParser\Node\Stmt\Function_;
2220
use PHPStan\Analyser\Scope;
2321
use PHPStan\Reflection\ClassReflection;
2422
use PHPStan\Reflection\FunctionReflection;
@@ -216,34 +214,6 @@ public function resolveFunctionLikeReflectionFromCall(
216214
return null;
217215
}
218216

219-
public function resolveMethodReflectionFromClassMethod(ClassMethod $classMethod, Scope $scope): ?MethodReflection
220-
{
221-
$classReflection = $scope->getClassReflection();
222-
if (! $classReflection instanceof ClassReflection) {
223-
return null;
224-
}
225-
226-
$className = $classReflection->getName();
227-
$methodName = $this->nodeNameResolver->getName($classMethod);
228-
229-
return $this->resolveMethodReflection($className, $methodName, $scope);
230-
}
231-
232-
public function resolveFunctionReflectionFromFunction(Function_ $function): ?FunctionReflection
233-
{
234-
$name = $this->nodeNameResolver->getName($function);
235-
if ($name === null) {
236-
return null;
237-
}
238-
239-
$functionName = new Name($name);
240-
if ($this->reflectionProvider->hasFunction($functionName, null)) {
241-
return $this->reflectionProvider->getFunction($functionName, null);
242-
}
243-
244-
return null;
245-
}
246-
247217
public function resolveMethodReflectionFromNew(New_ $new): ?MethodReflection
248218
{
249219
$newClassType = $this->nodeTypeResolver->getType($new->class);

0 commit comments

Comments
 (0)