Skip to content

Commit 4c32984

Browse files
committed
[cleanup] Add unused public, remove unused methods and ignore rest
1 parent f5c7bbd commit 4c32984

9 files changed

Lines changed: 25 additions & 73 deletions

File tree

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 & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
{
2424
public function __construct(
2525
private NodeNameResolver $nodeNameResolver,
26-
private ReflectionProvider $reflectionProvider,
2726
) {
2827
}
2928

@@ -42,29 +41,6 @@ public function hasPhpAttribute(Property | ClassLike | ClassMethod | Param $node
4241
return false;
4342
}
4443

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-
6844
/**
6945
* @param string[] $attributeClasses
7046
*/

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 & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -216,34 +216,6 @@ public function resolveFunctionLikeReflectionFromCall(
216216
return null;
217217
}
218218

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-
247219
public function resolveMethodReflectionFromNew(New_ $new): ?MethodReflection
248220
{
249221
$newClassType = $this->nodeTypeResolver->getType($new->class);

0 commit comments

Comments
 (0)