diff --git a/.github/workflows/test-rector.yml b/.github/workflows/test-rector.yml index dee7e96ea67f..e1420c965f37 100644 --- a/.github/workflows/test-rector.yml +++ b/.github/workflows/test-rector.yml @@ -12,7 +12,7 @@ on: - 'system/**' - '.github/workflows/test-rector.yml' - composer.json - - 'utils/Rector' + - 'utils/Rector/**' - 'rector.php' push: branches: @@ -23,7 +23,7 @@ on: - 'system/**' - '.github/workflows/test-rector.yml' - composer.json - - 'utils/Rector' + - 'utils/Rector/**' - 'rector.php' jobs: diff --git a/utils/Rector/UnderscoreToCamelCaseVariableNameRector.php b/utils/Rector/UnderscoreToCamelCaseVariableNameRector.php index 197528e79d84..5ba205ce43c2 100644 --- a/utils/Rector/UnderscoreToCamelCaseVariableNameRector.php +++ b/utils/Rector/UnderscoreToCamelCaseVariableNameRector.php @@ -5,15 +5,15 @@ namespace Utils\Rector; use Nette\Utils\Strings; +use PhpParser\Comment\Doc; use PhpParser\Node; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; -use Rector\BetterPhpDocParser\PhpDocManipulator\PropertyDocBlockManipulator; use Rector\Core\Php\ReservedKeywordAnalyzer; use Rector\Core\Rector\AbstractRector; -use Rector\Core\Util\StaticRectorStrings; use Rector\NodeTypeResolver\Node\AttributeKey; +use Symplify\PackageBuilder\Strings\StringFormatConverter; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -30,22 +30,22 @@ final class UnderscoreToCamelCaseVariableNameRector extends AbstractRector private const PARAM_NAME_REGEX = '#(?@param\s.*\s+\$)(?%s)#ms'; /** - * @var PropertyDocBlockManipulator + * @var ReservedKeywordAnalyzer */ - private $propertyDocBlockManipulator; + private $reservedKeywordAnalyzer; /** - * @var ReservedKeywordAnalyzer + * @var StringFormatConverter */ - private $reservedKeywordAnalyzer; + private $stringFormatConverter; public function __construct( - PropertyDocBlockManipulator $propertyDocBlockManipulator, - ReservedKeywordAnalyzer $reservedKeywordAnalyzer + ReservedKeywordAnalyzer $reservedKeywordAnalyzer, + StringFormatConverter $stringFormatConverter ) { - $this->propertyDocBlockManipulator = $propertyDocBlockManipulator; - $this->reservedKeywordAnalyzer = $reservedKeywordAnalyzer; + $this->reservedKeywordAnalyzer = $reservedKeywordAnalyzer; + $this->stringFormatConverter = $stringFormatConverter; } public function getRuleDefinition(): RuleDefinition @@ -109,7 +109,7 @@ public function refactor(Node $node): ?Node return null; } - $camelCaseName = StaticRectorStrings::underscoreToCamelCase($nodeName); + $camelCaseName = $this->stringFormatConverter->underscoreAndHyphenToCamelCase($nodeName); if ($camelCaseName === 'this') { return null; @@ -153,15 +153,23 @@ private function updateDocblock(Variable $variable, string $variableName, string return; } - if (! $match = Strings::match($docCommentText, sprintf(self::PARAM_NAME_REGEX, $variableName))) + if (! Strings::match($docCommentText, sprintf(self::PARAM_NAME_REGEX, $variableName))) { return; } - $this->propertyDocBlockManipulator->renameParameterNameInDocBlock( - $parentNode, - $match['paramName'], - $camelCaseName - ); + $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($parentNode); + $paramTagValueNodes = $phpDocInfo->getParamTagValueNodes(); + + foreach ($paramTagValueNodes as $paramTagValueNode) + { + if ($paramTagValueNode->parameterName === '$' . $variableName) + { + $paramTagValueNode->parameterName = '$' . $camelCaseName; + break; + } + } + + $parentNode->setDocComment(new Doc($phpDocInfo->getPhpDocNode()->__toString())); } }