![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/rector/rector/rules/DeadCode/PhpDoc/TagRemover/ |
<?php declare (strict_types=1); namespace Rector\DeadCode\PhpDoc\TagRemover; use PhpParser\Node\FunctionLike; use PHPStan\PhpDocParser\Ast\Node; use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\DeadCode\PhpDoc\DeadParamTagValueNodeAnalyzer; use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser; final class ParamTagRemover { /** * @readonly * @var \Rector\DeadCode\PhpDoc\DeadParamTagValueNodeAnalyzer */ private $deadParamTagValueNodeAnalyzer; public function __construct(DeadParamTagValueNodeAnalyzer $deadParamTagValueNodeAnalyzer) { $this->deadParamTagValueNodeAnalyzer = $deadParamTagValueNodeAnalyzer; } public function removeParamTagsIfUseless(PhpDocInfo $phpDocInfo, FunctionLike $functionLike) : bool { $hasChanged = \false; $phpDocNodeTraverser = new PhpDocNodeTraverser(); $phpDocNodeTraverser->traverseWithCallable($phpDocInfo->getPhpDocNode(), '', function (Node $docNode) use($functionLike, $phpDocInfo, &$hasChanged) : ?int { if (!$docNode instanceof PhpDocTagNode) { return null; } if (!$docNode->value instanceof ParamTagValueNode) { return null; } // handle only basic types, keep phpstan/psalm helper ones if ($docNode->name !== '@param') { return null; } // skip union types if ($docNode->value->type instanceof UnionTypeNode) { return null; } if (!$this->deadParamTagValueNodeAnalyzer->isDead($docNode->value, $functionLike)) { return null; } $phpDocInfo->markAsChanged(); $hasChanged = \true; return PhpDocNodeTraverser::NODE_REMOVE; }); return $hasChanged; } }