rector/packages/BetterPhpDocParser/PhpDocManipulator/PropertyDocBlockManipulator.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

37 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Rector\BetterPhpDocParser\PhpDocManipulator;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
use Rector\Naming\Contract\RenameValueObjectInterface;
use Rector\Naming\ValueObject\ParamRename;
final class PropertyDocBlockManipulator
{
public function __construct(
private readonly PhpDocInfoFactory $phpDocInfoFactory
) {
}
/**
* @param ParamRename $renameValueObject
*/
public function renameParameterNameInDocBlock(RenameValueObjectInterface $renameValueObject): void
{
$functionLike = $renameValueObject->getFunctionLike();
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike);
$paramTagValueNode = $phpDocInfo->getParamTagValueNodeByName($renameValueObject->getCurrentName());
if (! $paramTagValueNode instanceof ParamTagValueNode) {
return;
}
$paramTagValueNode->parameterName = '$' . $renameValueObject->getExpectedName();
$paramTagValueNode->setAttribute(PhpDocAttributeKey::ORIG_NODE, null);
}
}