rector/packages/NodeTypeResolver/PhpDoc/NodeAnalyzer/DocBlockTagReplacer.php
Abdul Malik Ikhsan fc10fce13d
[Rectify] [Php81] Enable Rectify on Readonly Property only (#1384)
* re-enable rectify and ecs

* [Rectify] [Php81] Enable Rectify on Readonly Property only

* comment

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
2021-12-04 15:32:52 +03:00

39 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\BetterPhpDocParser\Annotation\AnnotationNaming;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
final class DocBlockTagReplacer
{
public function __construct(
private readonly AnnotationNaming $annotationNaming
) {
}
public function replaceTagByAnother(PhpDocInfo $phpDocInfo, string $oldTag, string $newTag): void
{
$oldTag = $this->annotationNaming->normalizeName($oldTag);
$newTag = $this->annotationNaming->normalizeName($newTag);
$phpDocNode = $phpDocInfo->getPhpDocNode();
foreach ($phpDocNode->children as $key => $phpDocChildNode) {
if (! $phpDocChildNode instanceof PhpDocTagNode) {
continue;
}
if ($phpDocChildNode->name !== $oldTag) {
continue;
}
unset($phpDocNode->children[$key]);
$phpDocNode->children[] = new PhpDocTagNode($newTag, new GenericTagValueNode(''));
}
}
}