55namespace Utils \Rector ;
66
77use Nette \Utils \Strings ;
8+ use PhpParser \Comment \Doc ;
89use PhpParser \Node ;
910use PhpParser \Node \Expr \Variable ;
1011use PhpParser \Node \Stmt \ClassMethod ;
1112use PhpParser \Node \Stmt \Function_ ;
12- use Rector \BetterPhpDocParser \PhpDocManipulator \PropertyDocBlockManipulator ;
1313use Rector \Core \Php \ReservedKeywordAnalyzer ;
1414use Rector \Core \Rector \AbstractRector ;
15- use Rector \Core \Util \StaticRectorStrings ;
1615use Rector \NodeTypeResolver \Node \AttributeKey ;
16+ use Symplify \PackageBuilder \Strings \StringFormatConverter ;
1717use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
1818use Symplify \RuleDocGenerator \ValueObject \RuleDefinition ;
1919
@@ -30,22 +30,22 @@ final class UnderscoreToCamelCaseVariableNameRector extends AbstractRector
3030 private const PARAM_NAME_REGEX = '#(?<paramPrefix>@param\s.*\s+\$)(?<paramName>%s)#ms ' ;
3131
3232 /**
33- * @var PropertyDocBlockManipulator
33+ * @var ReservedKeywordAnalyzer
3434 */
35- private $ propertyDocBlockManipulator ;
35+ private $ reservedKeywordAnalyzer ;
3636
3737 /**
38- * @var ReservedKeywordAnalyzer
38+ * @var StringFormatConverter
3939 */
40- private $ reservedKeywordAnalyzer ;
40+ private $ stringFormatConverter ;
4141
4242 public function __construct (
43- PropertyDocBlockManipulator $ propertyDocBlockManipulator ,
44- ReservedKeywordAnalyzer $ reservedKeywordAnalyzer
43+ ReservedKeywordAnalyzer $ reservedKeywordAnalyzer ,
44+ StringFormatConverter $ stringFormatConverter
4545 )
4646 {
47- $ this ->propertyDocBlockManipulator = $ propertyDocBlockManipulator ;
48- $ this ->reservedKeywordAnalyzer = $ reservedKeywordAnalyzer ;
47+ $ this ->reservedKeywordAnalyzer = $ reservedKeywordAnalyzer ;
48+ $ this ->stringFormatConverter = $ stringFormatConverter ;
4949 }
5050
5151 public function getRuleDefinition (): RuleDefinition
@@ -109,7 +109,7 @@ public function refactor(Node $node): ?Node
109109 return null ;
110110 }
111111
112- $ camelCaseName = StaticRectorStrings:: underscoreToCamelCase ($ nodeName );
112+ $ camelCaseName = $ this -> stringFormatConverter -> underscoreAndHyphenToCamelCase ($ nodeName );
113113 if ($ camelCaseName === 'this ' )
114114 {
115115 return null ;
@@ -153,15 +153,23 @@ private function updateDocblock(Variable $variable, string $variableName, string
153153 return ;
154154 }
155155
156- if (! $ match = Strings::match ($ docCommentText , sprintf (self ::PARAM_NAME_REGEX , $ variableName )))
156+ if (! Strings::match ($ docCommentText , sprintf (self ::PARAM_NAME_REGEX , $ variableName )))
157157 {
158158 return ;
159159 }
160160
161- $ this ->propertyDocBlockManipulator ->renameParameterNameInDocBlock (
162- $ parentNode ,
163- $ match ['paramName ' ],
164- $ camelCaseName
165- );
161+ $ phpDocInfo = $ this ->phpDocInfoFactory ->createFromNodeOrEmpty ($ parentNode );
162+ $ paramTagValueNodes = $ phpDocInfo ->getParamTagValueNodes ();
163+
164+ foreach ($ paramTagValueNodes as $ paramTagValueNode )
165+ {
166+ if ($ paramTagValueNode ->parameterName === '$ ' . $ variableName )
167+ {
168+ $ paramTagValueNode ->parameterName = '$ ' . $ camelCaseName ;
169+ break ;
170+ }
171+ }
172+
173+ $ parentNode ->setDocComment (new Doc ($ phpDocInfo ->getPhpDocNode ()->__toString ()));
166174 }
167175}
0 commit comments