Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cleanup] Remove 73 unused public methods 🎄 #3245

Merged
merged 7 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"phpstan/phpstan-strict-rules": "^1.4.4",
"phpstan/phpstan-webmozart-assert": "^1.2.2",
"phpunit/phpunit": "^9.5.27",
"rector/phpstan-rules": "^0.6.1",
"rector/phpstan-rules": "^0.6.3",
"rector/rector-debugging": "dev-main",
"rector/rector-generator": "dev-main",
"spatie/enum": "^3.13",
Expand All @@ -61,7 +61,9 @@
"symplify/phpstan-rules": "^11.1.18",
"symplify/rule-doc-generator": "^11.1.18",
"symplify/vendor-patches": "^11.1.18",
"tomasvotruba/unused-public": "^0.0.23"
"tomasvotruba/cognitive-complexity": "^0.1.0",
"tomasvotruba/type-coverage": "^0.0.5",
"tomasvotruba/unused-public": "^0.0.26"
},
"replace": {
"rector/rector": "self.version",
Expand Down
2 changes: 0 additions & 2 deletions easy-ci.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Rector\Core\NodeDecorator\NamespacedNameDecorator;
use Rector\Core\NodeManipulator\MethodCallManipulator;
use Rector\Core\PhpParser\Node\NamedVariableFactory;
use Rector\Defluent\NodeAnalyzer\SameClassMethodCallAnalyzer;
use Rector\DependencyInjection\NodeManipulator\PropertyConstructorInjectionManipulator;
use Rector\FileSystemRector\Parser\FileInfoParser;
use Rector\Naming\Contract\AssignVariableNameResolverInterface;
Expand Down Expand Up @@ -80,7 +79,6 @@
PropertyConstructorInjectionManipulator::class,
// used in tests
FileInfoParser::class,
SameClassMethodCallAnalyzer::class,
AnnotationToAttributeMapperInterface::class,
TypeWithClassTypeSpecifierInterface::class,
ParentNodeReadAnalyzerInterface::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ public function testResolvesClass(string $filePath): void
foreach ($properties as $property) {
/** @var Property $property */
$phpDoc = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
/** @var VarTagValueNode $varTag */
$varTag = $phpDoc->getByType(VarTagValueNode::class)[0];
$value = $varTag->type->__toString();

$varTagValueNode = $phpDoc->getVarTagValueNode();
$this->assertInstanceOf(VarTagValueNode::class, $varTagValueNode);

$value = $varTagValueNode->type->__toString();
$propertyName = strtolower($this->nodeNameResolver->getName($property));

$result = $this->classAnnotationMatcher->resolveTagToKnownFullyQualifiedName($value, $property);
Expand Down
85 changes: 13 additions & 72 deletions packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
Expand Down Expand Up @@ -154,16 +153,6 @@ public function getReturnType(): Type
return $this->getTypeOrMixed($this->getReturnTagValue());
}

/**
* @template TNode as \PHPStan\PhpDocParser\Ast\Node
* @param class-string<TNode> $type
* @return TNode[]
*/
public function getByType(string $type): array
{
return $this->phpDocNodeByTypeFinder->findByType($this->phpDocNode, $type);
}

/**
* @param class-string<Node> $type
*/
Expand Down Expand Up @@ -223,6 +212,9 @@ public function getByAnnotationClasses(array $classes): ?DoctrineAnnotationTagVa
return $doctrineAnnotationTagValueNodes[0] ?? null;
}

/**
* @api doctrine/symfony
*/
public function getByAnnotationClass(string $class): ?DoctrineAnnotationTagValueNode
{
$doctrineAnnotationTagValueNodes = $this->phpDocNodeByTypeFinder->findDoctrineAnnotationsByClass(
Expand Down Expand Up @@ -268,15 +260,6 @@ public function findOneByAnnotationClass(string $desiredClass): ?DoctrineAnnotat
return $foundTagValueNodes[0] ?? null;
}

/**
* @param class-string $desiredClass
* @return DoctrineAnnotationTagValueNode[]
*/
public function findByAnnotationClass(string $desiredClass): array
{
return $this->phpDocNodeByTypeFinder->findDoctrineAnnotationsByClass($this->phpDocNode, $desiredClass);
}

/**
* @template T of \PHPStan\PhpDocParser\Ast\Node
* @param class-string<T> $typeToRemove
Expand Down Expand Up @@ -310,25 +293,6 @@ public function removeByType(string $typeToRemove): void
});
}

/**
* @return array<string, Type>
*/
public function getParamTypesByName(): array
{
$paramTypesByName = [];

foreach ($this->phpDocNode->getParamTagValues() as $paramTagValueNode) {
$parameterType = $this->staticTypeMapper->mapPHPStanPhpDocTypeToPHPStanType(
$paramTagValueNode,
$this->node
);

$paramTypesByName[$paramTagValueNode->parameterName] = $parameterType;
}

return $paramTypesByName;
}

public function addTagValueNode(PhpDocTagValueNode $phpDocTagValueNode): void
{
if ($phpDocTagValueNode instanceof DoctrineAnnotationTagValueNode) {
Expand Down Expand Up @@ -422,25 +386,6 @@ public function getTemplateTagValueNodes(): array
return $this->phpDocNode->getTemplateTagValues();
}

public function hasInheritDoc(): bool
{
if ($this->hasByNames(['inheritdoc', 'inheritDoc'])) {
return true;
}

foreach ($this->phpDocNode->children as $children) {
if (! $children instanceof PhpDocTextNode) {
continue;
}

if (in_array($children->text, ['{@inheritdoc}', '{@inheritDoc}'], true)) {
return true;
}
}

return false;
}

/**
* @deprecated
* Should be handled by attributes of phpdoc node - if stard_and_end is missing in one of nodes, it has been changed
Expand Down Expand Up @@ -475,19 +420,6 @@ public function hasChanged(): bool
return $changedPhpDocNodeVisitor->hasChanged();
}

/**
* @return string[]
*/
public function getMethodTagNames(): array
{
$methodTagNames = [];
foreach ($this->phpDocNode->getMethodTagValues() as $methodTagValueNode) {
$methodTagNames[] = $methodTagValueNode->methodName;
}

return $methodTagNames;
}

public function makeMultiLined(): void
{
$this->isSingleLine = false;
Expand All @@ -498,7 +430,7 @@ public function getNode(): \PhpParser\Node
return $this->node;
}

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

/**
* @param class-string $desiredClass
* @return DoctrineAnnotationTagValueNode[]
*/
private function findByAnnotationClass(string $desiredClass): array
{
return $this->phpDocNodeByTypeFinder->findDoctrineAnnotationsByClass($this->phpDocNode, $desiredClass);
}

private function getTypeOrMixed(?PhpDocTagValueNode $phpDocTagValueNode): MixedType | Type
{
if ($phpDocTagValueNode === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ public function copyPropertyDocToParam(Property $property, Param $param): void
$this->processKeepComments($property, $param);
}

/**
* @api doctrine
*/
public function changeVarTypeNode(PhpDocInfo $phpDocInfo, TypeNode $typeNode): void
{
// add completely new one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,18 @@
namespace Rector\BetterPhpDocParser\PhpDocManipulator;

use PhpParser\Node;
use PhpParser\Node\Stmt\Expression;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\ValueObject\Type\FullyQualifiedIdentifierTypeNode;
use Rector\Core\PhpParser\Node\BetterNodeFinder;

final class VarAnnotationManipulator
{
public function __construct(
private readonly PhpDocInfoFactory $phpDocInfoFactory,
private readonly PhpDocTypeChanger $phpDocTypeChanger,
private readonly BetterNodeFinder $betterNodeFinder
) {
}

public function decorateNodeWithInlineVarType(
Node $node,
TypeWithClassName $typeWithClassName,
string $variableName
): void {
$phpDocInfo = $this->resolvePhpDocInfo($node);

// already done
if ($phpDocInfo->getVarTagValueNode() !== null) {
return;
}

$fullyQualifiedIdentifierTypeNode = new FullyQualifiedIdentifierTypeNode($typeWithClassName->getClassName());

$varTagValueNode = new VarTagValueNode($fullyQualifiedIdentifierTypeNode, '$' . $variableName, '');
$phpDocInfo->addTagValueNode($varTagValueNode);
$phpDocInfo->makeSingleLined();
}

/**
* @api
*/
Expand All @@ -55,18 +29,4 @@ public function decorateNodeWithType(Node $node, Type $staticType): void
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $staticType);
}

private function resolvePhpDocInfo(Node $node): PhpDocInfo
{
$currentStmt = $this->betterNodeFinder->resolveCurrentStatement($node);
if ($currentStmt instanceof Expression) {
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($currentStmt);
} else {
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
}

$phpDocInfo->makeSingleLined();

return $phpDocInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public function __construct(
) {
}

/**
* @api doctrine
*/
public function resolveTagToKnownFullyQualifiedName(string $tag, Property $property): ?string
{
return $this->_resolveTagFullyQualifiedName($tag, $property, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function resolveAnnotationMethodCall(BetterTokenIterator $tokenIterator):
}

/**
* @api tests
* @see https://github.com/doctrine/annotations/blob/c66f06b7c83e9a2a7523351a9d5a4b55f885e574/lib/Doctrine/Common/Annotations/DocParser.php#L1215-L1224
* @return CurlyListNode|string|array<mixed>|ConstExprNode|DoctrineAnnotationTagValueNode
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function printFormatPreserving(PhpDocInfo $phpDocInfo): string
return Strings::replace($phpDocString, self::CALLABLE_REGEX, 'callable(');
}

public function getCurrentPhpDocInfo(): PhpDocInfo
private function getCurrentPhpDocInfo(): PhpDocInfo
{
if ($this->phpDocInfo === null) {
throw new ShouldNotHappenException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,34 +97,6 @@ public function printFromTo(int $from, int $to): string
return $content;
}

public function print(): string
{
$content = '';
foreach ($this->getTokens() as $token) {
$content .= $token[0];
}

return $content;
}

public function nextTokenType(): ?int
{
$tokens = $this->getTokens();

// does next token exist?
$nextIndex = $this->currentPosition() + 1;
if (! isset($tokens[$nextIndex])) {
return null;
}

$this->pushSavePoint();
$this->next();
$nextTokenType = $this->currentTokenType();
$this->rollback();

return $nextTokenType;
}

public function currentPosition(): int
{
return $this->privatesAccessor->getPrivateProperty($this, self::INDEX);
Expand Down Expand Up @@ -161,4 +133,22 @@ public function containsTokenType(int $type): bool

return false;
}

private function nextTokenType(): ?int
{
$tokens = $this->getTokens();

// does next token exist?
$nextIndex = $this->currentPosition() + 1;
if (! isset($tokens[$nextIndex])) {
return null;
}

$this->pushSavePoint();
$this->next();
$nextTokenType = $this->currentTokenType();
$this->rollback();

return $nextTokenType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public function __construct(
) {
}

/**
* @api
*/
public function removeValue(string $desiredKey): void
{
foreach ($this->values as $key => $value) {
Expand Down
9 changes: 0 additions & 9 deletions packages/BetterPhpDocParser/ValueObject/StartAndEnd.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,4 @@ public function getEnd(): int
{
return $this->end;
}

public function contains(int $position): bool
{
if ($position < $this->start) {
return false;
}

return $position < $this->end;
}
}
3 changes: 3 additions & 0 deletions packages/Caching/CacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public function __construct(
) {
}

/**
* @api config factory
*/
public function create(): Cache
{
$cacheDirectory = $this->parameterProvider->provideStringParameter(Option::CACHE_DIR);
Expand Down
Loading