32
32
use PHPStan \PhpDocParser \Parser \PhpDocParser ;
33
33
use PHPStan \PhpDocParser \Parser \TokenIterator ;
34
34
use PHPStan \PhpDocParser \Parser \TypeParser ;
35
+ use PHPStan \PhpDocParser \ParserConfig ;
35
36
36
37
/**
37
38
* Verifies order of types in type hints
@@ -128,7 +129,7 @@ public function process(File $phpcsFile, $stackPtr)
128
129
'%s type hint is not formatted properly, expected "%s" ' ,
129
130
$ tag ,
130
131
'IncorrectFormat ' ,
131
- [$ tokens [$ tag ]['content ' ], $ sortedTypeHint ]
132
+ [$ tokens [$ tag ]['content ' ], $ sortedTypeHint ],
132
133
);
133
134
if (!$ fix ) {
134
135
continue ;
@@ -140,7 +141,7 @@ public function process(File $phpcsFile, $stackPtr)
140
141
'%s %s %s ' ,
141
142
$ sortedTypeHint ,
142
143
$ valueNode ->variableName ,
143
- $ valueNode ->description
144
+ $ valueNode ->description ,
144
145
));
145
146
if ($ tagComment [-1 ] === ' ' ) {
146
147
// tags above variables in code have a trailing space
@@ -152,13 +153,13 @@ public function process(File $phpcsFile, $stackPtr)
152
153
$ sortedTypeHint ,
153
154
$ valueNode ->isVariadic ? '... ' : '' ,
154
155
$ valueNode ->parameterName ,
155
- $ valueNode ->description
156
+ $ valueNode ->description ,
156
157
));
157
158
} elseif ($ valueNode instanceof ReturnTagValueNode) {
158
159
$ newComment = trim (sprintf (
159
160
'%s %s ' ,
160
161
$ sortedTypeHint ,
161
- $ valueNode ->description
162
+ $ valueNode ->description ,
162
163
));
163
164
}
164
165
@@ -278,10 +279,10 @@ protected function getSortedTypeHint(array $types): string
278
279
protected function renderUnionTypes (array $ typeNodes ): string
279
280
{
280
281
// Remove parenthesis added by phpstan around union and intersection types
281
- return preg_replace (
282
+ return ( string ) preg_replace (
282
283
['/ ([\|&]) / ' , '/<\(/ ' , '/\)>/ ' , '/\), / ' , '/, \(/ ' ],
283
284
['${1} ' , '< ' , '> ' , ', ' , ', ' ],
284
- implode ('| ' , $ typeNodes )
285
+ implode ('| ' , $ typeNodes ),
285
286
);
286
287
}
287
288
@@ -294,13 +295,16 @@ protected static function getValueNode(string $tagName, string $tagComment): Php
294
295
{
295
296
static $ phpDocParser ;
296
297
if (!$ phpDocParser ) {
297
- $ constExprParser = new ConstExprParser ();
298
- $ phpDocParser = new PhpDocParser (new TypeParser ($ constExprParser ), $ constExprParser );
298
+ $ config = new ParserConfig (usedAttributes: ['lines ' => true , 'indexes ' => true ]);
299
+
300
+ $ constExprParser = new ConstExprParser ($ config );
301
+ $ phpDocParser = new PhpDocParser ($ config , new TypeParser ($ config , $ constExprParser ), $ constExprParser );
299
302
}
300
303
301
304
static $ phpDocLexer ;
302
305
if (!$ phpDocLexer ) {
303
- $ phpDocLexer = new Lexer ();
306
+ $ config = new ParserConfig (usedAttributes: ['lines ' => true , 'indexes ' => true ]);
307
+ $ phpDocLexer = new Lexer ($ config );
304
308
}
305
309
306
310
return $ phpDocParser ->parseTagValue (new TokenIterator ($ phpDocLexer ->tokenize ($ tagComment )), $ tagName );
0 commit comments