2020-07-27 12:49:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Rector\BetterPhpDocParser\PhpDocManipulator;
|
|
|
|
|
2021-01-20 00:29:52 +01:00
|
|
|
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
|
2021-01-19 02:15:32 +01:00
|
|
|
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
2021-04-04 11:01:11 +02:00
|
|
|
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
|
2020-11-16 17:50:38 +00:00
|
|
|
use Rector\Naming\Contract\RenameValueObjectInterface;
|
2020-10-03 21:18:12 +02:00
|
|
|
use Rector\Naming\ValueObject\ParamRename;
|
2020-07-27 12:49:15 +02:00
|
|
|
|
|
|
|
final class PropertyDocBlockManipulator
|
|
|
|
{
|
2021-01-19 02:15:32 +01:00
|
|
|
/**
|
|
|
|
* @var PhpDocInfoFactory
|
|
|
|
*/
|
|
|
|
private $phpDocInfoFactory;
|
|
|
|
|
|
|
|
public function __construct(PhpDocInfoFactory $phpDocInfoFactory)
|
|
|
|
{
|
|
|
|
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
|
|
|
}
|
|
|
|
|
2020-10-03 21:18:12 +02:00
|
|
|
/**
|
|
|
|
* @param ParamRename $renameValueObject
|
|
|
|
*/
|
|
|
|
public function renameParameterNameInDocBlock(RenameValueObjectInterface $renameValueObject): void
|
2020-07-27 12:49:15 +02:00
|
|
|
{
|
2020-11-16 17:50:38 +00:00
|
|
|
$functionLike = $renameValueObject->getFunctionLike();
|
|
|
|
|
2021-01-19 02:15:32 +01:00
|
|
|
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike);
|
2020-10-03 21:18:12 +02:00
|
|
|
$paramTagValueNode = $phpDocInfo->getParamTagValueNodeByName($renameValueObject->getCurrentName());
|
2021-01-20 00:29:52 +01:00
|
|
|
if (! $paramTagValueNode instanceof ParamTagValueNode) {
|
2020-07-27 12:49:15 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-03 21:18:12 +02:00
|
|
|
$paramTagValueNode->parameterName = '$' . $renameValueObject->getExpectedName();
|
2021-04-06 19:33:09 +02:00
|
|
|
$paramTagValueNode->setAttribute(PhpDocAttributeKey::ORIG_NODE, null);
|
2020-07-27 12:49:15 +02:00
|
|
|
}
|
|
|
|
}
|