5
5
namespace Utils \Rector ;
6
6
7
7
use Nette \Utils \Strings ;
8
+ use PhpParser \Comment \Doc ;
8
9
use PhpParser \Node ;
9
10
use PhpParser \Node \Expr \Variable ;
10
11
use PhpParser \Node \Stmt \ClassMethod ;
11
12
use PhpParser \Node \Stmt \Function_ ;
12
- use Rector \BetterPhpDocParser \PhpDocManipulator \PropertyDocBlockManipulator ;
13
13
use Rector \Core \Php \ReservedKeywordAnalyzer ;
14
14
use Rector \Core \Rector \AbstractRector ;
15
- use Rector \Core \Util \StaticRectorStrings ;
16
15
use Rector \NodeTypeResolver \Node \AttributeKey ;
16
+ use Symplify \PackageBuilder \Strings \StringFormatConverter ;
17
17
use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
18
18
use Symplify \RuleDocGenerator \ValueObject \RuleDefinition ;
19
19
@@ -30,22 +30,22 @@ final class UnderscoreToCamelCaseVariableNameRector extends AbstractRector
30
30
private const PARAM_NAME_REGEX = '#(?<paramPrefix>@param\s.*\s+\$)(?<paramName>%s)#ms ' ;
31
31
32
32
/**
33
- * @var PropertyDocBlockManipulator
33
+ * @var ReservedKeywordAnalyzer
34
34
*/
35
- private $ propertyDocBlockManipulator ;
35
+ private $ reservedKeywordAnalyzer ;
36
36
37
37
/**
38
- * @var ReservedKeywordAnalyzer
38
+ * @var StringFormatConverter
39
39
*/
40
- private $ reservedKeywordAnalyzer ;
40
+ private $ stringFormatConverter ;
41
41
42
42
public function __construct (
43
- PropertyDocBlockManipulator $ propertyDocBlockManipulator ,
44
- ReservedKeywordAnalyzer $ reservedKeywordAnalyzer
43
+ ReservedKeywordAnalyzer $ reservedKeywordAnalyzer ,
44
+ StringFormatConverter $ stringFormatConverter
45
45
)
46
46
{
47
- $ this ->propertyDocBlockManipulator = $ propertyDocBlockManipulator ;
48
- $ this ->reservedKeywordAnalyzer = $ reservedKeywordAnalyzer ;
47
+ $ this ->reservedKeywordAnalyzer = $ reservedKeywordAnalyzer ;
48
+ $ this ->stringFormatConverter = $ stringFormatConverter ;
49
49
}
50
50
51
51
public function getRuleDefinition (): RuleDefinition
@@ -109,7 +109,7 @@ public function refactor(Node $node): ?Node
109
109
return null ;
110
110
}
111
111
112
- $ camelCaseName = StaticRectorStrings:: underscoreToCamelCase ($ nodeName );
112
+ $ camelCaseName = $ this -> stringFormatConverter -> underscoreAndHyphenToCamelCase ($ nodeName );
113
113
if ($ camelCaseName === 'this ' )
114
114
{
115
115
return null ;
@@ -153,15 +153,23 @@ private function updateDocblock(Variable $variable, string $variableName, string
153
153
return ;
154
154
}
155
155
156
- if (! $ match = Strings::match ($ docCommentText , sprintf (self ::PARAM_NAME_REGEX , $ variableName )))
156
+ if (! Strings::match ($ docCommentText , sprintf (self ::PARAM_NAME_REGEX , $ variableName )))
157
157
{
158
158
return ;
159
159
}
160
160
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 ()));
166
174
}
167
175
}
0 commit comments