mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-13 06:32:22 +00:00
fc10fce13d
* 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>
39 lines
1.1 KiB
PHP
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(''));
|
|
}
|
|
}
|
|
}
|