Skip to content

Commit bfa1891

Browse files
authored
[cleanup] Remove 73 unused public methods (rectorphp#3245)
1 parent 8862942 commit bfa1891

File tree

113 files changed

+333
-927
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+333
-927
lines changed

composer.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"phpstan/phpstan-strict-rules": "^1.4.4",
5050
"phpstan/phpstan-webmozart-assert": "^1.2.2",
5151
"phpunit/phpunit": "^9.5.27",
52-
"rector/phpstan-rules": "^0.6.1",
52+
"rector/phpstan-rules": "^0.6.3",
5353
"rector/rector-debugging": "dev-main",
5454
"rector/rector-generator": "dev-main",
5555
"spatie/enum": "^3.13",
@@ -61,7 +61,9 @@
6161
"symplify/phpstan-rules": "^11.1.18",
6262
"symplify/rule-doc-generator": "^11.1.18",
6363
"symplify/vendor-patches": "^11.1.18",
64-
"tomasvotruba/unused-public": "^0.0.23"
64+
"tomasvotruba/cognitive-complexity": "^0.1.0",
65+
"tomasvotruba/type-coverage": "^0.0.5",
66+
"tomasvotruba/unused-public": "^0.0.26"
6567
},
6668
"replace": {
6769
"rector/rector": "self.version",

easy-ci.php

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Rector\Core\NodeDecorator\NamespacedNameDecorator;
1818
use Rector\Core\NodeManipulator\MethodCallManipulator;
1919
use Rector\Core\PhpParser\Node\NamedVariableFactory;
20-
use Rector\Defluent\NodeAnalyzer\SameClassMethodCallAnalyzer;
2120
use Rector\DependencyInjection\NodeManipulator\PropertyConstructorInjectionManipulator;
2221
use Rector\FileSystemRector\Parser\FileInfoParser;
2322
use Rector\Naming\Contract\AssignVariableNameResolverInterface;
@@ -80,7 +79,6 @@
8079
PropertyConstructorInjectionManipulator::class,
8180
// used in tests
8281
FileInfoParser::class,
83-
SameClassMethodCallAnalyzer::class,
8482
AnnotationToAttributeMapperInterface::class,
8583
TypeWithClassTypeSpecifierInterface::class,
8684
ParentNodeReadAnalyzerInterface::class,

packages-tests/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher/ResolveTagToKnownFullyQualifiedNameTest.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ public function testResolvesClass(string $filePath): void
5050
foreach ($properties as $property) {
5151
/** @var Property $property */
5252
$phpDoc = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
53-
/** @var VarTagValueNode $varTag */
54-
$varTag = $phpDoc->getByType(VarTagValueNode::class)[0];
55-
$value = $varTag->type->__toString();
53+
54+
$varTagValueNode = $phpDoc->getVarTagValueNode();
55+
$this->assertInstanceOf(VarTagValueNode::class, $varTagValueNode);
56+
57+
$value = $varTagValueNode->type->__toString();
5658
$propertyName = strtolower($this->nodeNameResolver->getName($property));
5759

5860
$result = $this->classAnnotationMatcher->resolveTagToKnownFullyQualifiedName($value, $property);

packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php

+13-72
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
1313
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
1414
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
15-
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode;
1615
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
1716
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
1817
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
@@ -154,16 +153,6 @@ public function getReturnType(): Type
154153
return $this->getTypeOrMixed($this->getReturnTagValue());
155154
}
156155

157-
/**
158-
* @template TNode as \PHPStan\PhpDocParser\Ast\Node
159-
* @param class-string<TNode> $type
160-
* @return TNode[]
161-
*/
162-
public function getByType(string $type): array
163-
{
164-
return $this->phpDocNodeByTypeFinder->findByType($this->phpDocNode, $type);
165-
}
166-
167156
/**
168157
* @param class-string<Node> $type
169158
*/
@@ -223,6 +212,9 @@ public function getByAnnotationClasses(array $classes): ?DoctrineAnnotationTagVa
223212
return $doctrineAnnotationTagValueNodes[0] ?? null;
224213
}
225214

215+
/**
216+
* @api doctrine/symfony
217+
*/
226218
public function getByAnnotationClass(string $class): ?DoctrineAnnotationTagValueNode
227219
{
228220
$doctrineAnnotationTagValueNodes = $this->phpDocNodeByTypeFinder->findDoctrineAnnotationsByClass(
@@ -268,15 +260,6 @@ public function findOneByAnnotationClass(string $desiredClass): ?DoctrineAnnotat
268260
return $foundTagValueNodes[0] ?? null;
269261
}
270262

271-
/**
272-
* @param class-string $desiredClass
273-
* @return DoctrineAnnotationTagValueNode[]
274-
*/
275-
public function findByAnnotationClass(string $desiredClass): array
276-
{
277-
return $this->phpDocNodeByTypeFinder->findDoctrineAnnotationsByClass($this->phpDocNode, $desiredClass);
278-
}
279-
280263
/**
281264
* @template T of \PHPStan\PhpDocParser\Ast\Node
282265
* @param class-string<T> $typeToRemove
@@ -310,25 +293,6 @@ public function removeByType(string $typeToRemove): void
310293
});
311294
}
312295

313-
/**
314-
* @return array<string, Type>
315-
*/
316-
public function getParamTypesByName(): array
317-
{
318-
$paramTypesByName = [];
319-
320-
foreach ($this->phpDocNode->getParamTagValues() as $paramTagValueNode) {
321-
$parameterType = $this->staticTypeMapper->mapPHPStanPhpDocTypeToPHPStanType(
322-
$paramTagValueNode,
323-
$this->node
324-
);
325-
326-
$paramTypesByName[$paramTagValueNode->parameterName] = $parameterType;
327-
}
328-
329-
return $paramTypesByName;
330-
}
331-
332296
public function addTagValueNode(PhpDocTagValueNode $phpDocTagValueNode): void
333297
{
334298
if ($phpDocTagValueNode instanceof DoctrineAnnotationTagValueNode) {
@@ -422,25 +386,6 @@ public function getTemplateTagValueNodes(): array
422386
return $this->phpDocNode->getTemplateTagValues();
423387
}
424388

425-
public function hasInheritDoc(): bool
426-
{
427-
if ($this->hasByNames(['inheritdoc', 'inheritDoc'])) {
428-
return true;
429-
}
430-
431-
foreach ($this->phpDocNode->children as $children) {
432-
if (! $children instanceof PhpDocTextNode) {
433-
continue;
434-
}
435-
436-
if (in_array($children->text, ['{@inheritdoc}', '{@inheritDoc}'], true)) {
437-
return true;
438-
}
439-
}
440-
441-
return false;
442-
}
443-
444389
/**
445390
* @deprecated
446391
* Should be handled by attributes of phpdoc node - if stard_and_end is missing in one of nodes, it has been changed
@@ -475,19 +420,6 @@ public function hasChanged(): bool
475420
return $changedPhpDocNodeVisitor->hasChanged();
476421
}
477422

478-
/**
479-
* @return string[]
480-
*/
481-
public function getMethodTagNames(): array
482-
{
483-
$methodTagNames = [];
484-
foreach ($this->phpDocNode->getMethodTagValues() as $methodTagValueNode) {
485-
$methodTagNames[] = $methodTagValueNode->methodName;
486-
}
487-
488-
return $methodTagNames;
489-
}
490-
491423
public function makeMultiLined(): void
492424
{
493425
$this->isSingleLine = false;
@@ -498,7 +430,7 @@ public function getNode(): \PhpParser\Node
498430
return $this->node;
499431
}
500432

501-
public function resolveNameForPhpDocTagValueNode(PhpDocTagValueNode $phpDocTagValueNode): ?string
433+
private function resolveNameForPhpDocTagValueNode(PhpDocTagValueNode $phpDocTagValueNode): ?string
502434
{
503435
foreach (self::TAGS_TYPES_TO_NAMES as $tagValueNodeType => $name) {
504436
/** @var class-string<PhpDocTagNode> $tagValueNodeType */
@@ -510,6 +442,15 @@ public function resolveNameForPhpDocTagValueNode(PhpDocTagValueNode $phpDocTagVa
510442
return null;
511443
}
512444

445+
/**
446+
* @param class-string $desiredClass
447+
* @return DoctrineAnnotationTagValueNode[]
448+
*/
449+
private function findByAnnotationClass(string $desiredClass): array
450+
{
451+
return $this->phpDocNodeByTypeFinder->findDoctrineAnnotationsByClass($this->phpDocNode, $desiredClass);
452+
}
453+
513454
private function getTypeOrMixed(?PhpDocTagValueNode $phpDocTagValueNode): MixedType | Type
514455
{
515456
if ($phpDocTagValueNode === null) {

packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTypeChanger.php

+3
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ public function copyPropertyDocToParam(Property $property, Param $param): void
240240
$this->processKeepComments($property, $param);
241241
}
242242

243+
/**
244+
* @api doctrine
245+
*/
243246
public function changeVarTypeNode(PhpDocInfo $phpDocInfo, TypeNode $typeNode): void
244247
{
245248
// add completely new one

packages/BetterPhpDocParser/PhpDocManipulator/VarAnnotationManipulator.php

-40
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,18 @@
55
namespace Rector\BetterPhpDocParser\PhpDocManipulator;
66

77
use PhpParser\Node;
8-
use PhpParser\Node\Stmt\Expression;
9-
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
108
use PHPStan\Type\MixedType;
119
use PHPStan\Type\Type;
12-
use PHPStan\Type\TypeWithClassName;
13-
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
1410
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
15-
use Rector\BetterPhpDocParser\ValueObject\Type\FullyQualifiedIdentifierTypeNode;
16-
use Rector\Core\PhpParser\Node\BetterNodeFinder;
1711

1812
final class VarAnnotationManipulator
1913
{
2014
public function __construct(
2115
private readonly PhpDocInfoFactory $phpDocInfoFactory,
2216
private readonly PhpDocTypeChanger $phpDocTypeChanger,
23-
private readonly BetterNodeFinder $betterNodeFinder
2417
) {
2518
}
2619

27-
public function decorateNodeWithInlineVarType(
28-
Node $node,
29-
TypeWithClassName $typeWithClassName,
30-
string $variableName
31-
): void {
32-
$phpDocInfo = $this->resolvePhpDocInfo($node);
33-
34-
// already done
35-
if ($phpDocInfo->getVarTagValueNode() !== null) {
36-
return;
37-
}
38-
39-
$fullyQualifiedIdentifierTypeNode = new FullyQualifiedIdentifierTypeNode($typeWithClassName->getClassName());
40-
41-
$varTagValueNode = new VarTagValueNode($fullyQualifiedIdentifierTypeNode, '$' . $variableName, '');
42-
$phpDocInfo->addTagValueNode($varTagValueNode);
43-
$phpDocInfo->makeSingleLined();
44-
}
45-
4620
/**
4721
* @api
4822
*/
@@ -55,18 +29,4 @@ public function decorateNodeWithType(Node $node, Type $staticType): void
5529
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
5630
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $staticType);
5731
}
58-
59-
private function resolvePhpDocInfo(Node $node): PhpDocInfo
60-
{
61-
$currentStmt = $this->betterNodeFinder->resolveCurrentStatement($node);
62-
if ($currentStmt instanceof Expression) {
63-
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($currentStmt);
64-
} else {
65-
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
66-
}
67-
68-
$phpDocInfo->makeSingleLined();
69-
70-
return $phpDocInfo;
71-
}
7232
}

packages/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher.php

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public function __construct(
3232
) {
3333
}
3434

35+
/**
36+
* @api doctrine
37+
*/
3538
public function resolveTagToKnownFullyQualifiedName(string $tag, Property $property): ?string
3639
{
3740
return $this->_resolveTagFullyQualifiedName($tag, $property, true);

packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function resolveAnnotationMethodCall(BetterTokenIterator $tokenIterator):
4747
}
4848

4949
/**
50+
* @api tests
5051
* @see https://github.com/doctrine/annotations/blob/c66f06b7c83e9a2a7523351a9d5a4b55f885e574/lib/Doctrine/Common/Annotations/DocParser.php#L1215-L1224
5152
* @return CurlyListNode|string|array<mixed>|ConstExprNode|DoctrineAnnotationTagValueNode
5253
*/

packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function printFormatPreserving(PhpDocInfo $phpDocInfo): string
135135
return Strings::replace($phpDocString, self::CALLABLE_REGEX, 'callable(');
136136
}
137137

138-
public function getCurrentPhpDocInfo(): PhpDocInfo
138+
private function getCurrentPhpDocInfo(): PhpDocInfo
139139
{
140140
if ($this->phpDocInfo === null) {
141141
throw new ShouldNotHappenException();

packages/BetterPhpDocParser/ValueObject/Parser/BetterTokenIterator.php

+18-28
Original file line numberDiff line numberDiff line change
@@ -97,34 +97,6 @@ public function printFromTo(int $from, int $to): string
9797
return $content;
9898
}
9999

100-
public function print(): string
101-
{
102-
$content = '';
103-
foreach ($this->getTokens() as $token) {
104-
$content .= $token[0];
105-
}
106-
107-
return $content;
108-
}
109-
110-
public function nextTokenType(): ?int
111-
{
112-
$tokens = $this->getTokens();
113-
114-
// does next token exist?
115-
$nextIndex = $this->currentPosition() + 1;
116-
if (! isset($tokens[$nextIndex])) {
117-
return null;
118-
}
119-
120-
$this->pushSavePoint();
121-
$this->next();
122-
$nextTokenType = $this->currentTokenType();
123-
$this->rollback();
124-
125-
return $nextTokenType;
126-
}
127-
128100
public function currentPosition(): int
129101
{
130102
return $this->privatesAccessor->getPrivateProperty($this, self::INDEX);
@@ -161,4 +133,22 @@ public function containsTokenType(int $type): bool
161133

162134
return false;
163135
}
136+
137+
private function nextTokenType(): ?int
138+
{
139+
$tokens = $this->getTokens();
140+
141+
// does next token exist?
142+
$nextIndex = $this->currentPosition() + 1;
143+
if (! isset($tokens[$nextIndex])) {
144+
return null;
145+
}
146+
147+
$this->pushSavePoint();
148+
$this->next();
149+
$nextTokenType = $this->currentTokenType();
150+
$this->rollback();
151+
152+
return $nextTokenType;
153+
}
164154
}

packages/BetterPhpDocParser/ValueObject/PhpDoc/DoctrineAnnotation/AbstractValuesAwareNode.php

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public function __construct(
2525
) {
2626
}
2727

28+
/**
29+
* @api
30+
*/
2831
public function removeValue(string $desiredKey): void
2932
{
3033
foreach ($this->values as $key => $value) {

packages/BetterPhpDocParser/ValueObject/StartAndEnd.php

-9
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,4 @@ public function getEnd(): int
2626
{
2727
return $this->end;
2828
}
29-
30-
public function contains(int $position): bool
31-
{
32-
if ($position < $this->start) {
33-
return false;
34-
}
35-
36-
return $position < $this->end;
37-
}
3829
}

packages/Caching/CacheFactory.php

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public function __construct(
1818
) {
1919
}
2020

21+
/**
22+
* @api config factory
23+
*/
2124
public function create(): Cache
2225
{
2326
$cacheDirectory = $this->parameterProvider->provideStringParameter(Option::CACHE_DIR);

0 commit comments

Comments
 (0)