3232use PHPStan \PhpDocParser \Parser \PhpDocParser ;
3333use PHPStan \PhpDocParser \Parser \TokenIterator ;
3434use PHPStan \PhpDocParser \Parser \TypeParser ;
35+ use PHPStan \PhpDocParser \ParserConfig ;
3536
3637/**
3738 * Verifies order of types in type hints
@@ -128,7 +129,7 @@ public function process(File $phpcsFile, $stackPtr)
128129 '%s type hint is not formatted properly, expected "%s" ' ,
129130 $ tag ,
130131 'IncorrectFormat ' ,
131- [$ tokens [$ tag ]['content ' ], $ sortedTypeHint ]
132+ [$ tokens [$ tag ]['content ' ], $ sortedTypeHint ],
132133 );
133134 if (!$ fix ) {
134135 continue ;
@@ -140,7 +141,7 @@ public function process(File $phpcsFile, $stackPtr)
140141 '%s %s %s ' ,
141142 $ sortedTypeHint ,
142143 $ valueNode ->variableName ,
143- $ valueNode ->description
144+ $ valueNode ->description ,
144145 ));
145146 if ($ tagComment [-1 ] === ' ' ) {
146147 // tags above variables in code have a trailing space
@@ -152,13 +153,13 @@ public function process(File $phpcsFile, $stackPtr)
152153 $ sortedTypeHint ,
153154 $ valueNode ->isVariadic ? '... ' : '' ,
154155 $ valueNode ->parameterName ,
155- $ valueNode ->description
156+ $ valueNode ->description ,
156157 ));
157158 } elseif ($ valueNode instanceof ReturnTagValueNode) {
158159 $ newComment = trim (sprintf (
159160 '%s %s ' ,
160161 $ sortedTypeHint ,
161- $ valueNode ->description
162+ $ valueNode ->description ,
162163 ));
163164 }
164165
@@ -278,10 +279,10 @@ protected function getSortedTypeHint(array $types): string
278279 protected function renderUnionTypes (array $ typeNodes ): string
279280 {
280281 // Remove parenthesis added by phpstan around union and intersection types
281- return preg_replace (
282+ return ( string ) preg_replace (
282283 ['/ ([\|&]) / ' , '/<\(/ ' , '/\)>/ ' , '/\), / ' , '/, \(/ ' ],
283284 ['${1} ' , '< ' , '> ' , ', ' , ', ' ],
284- implode ('| ' , $ typeNodes )
285+ implode ('| ' , $ typeNodes ),
285286 );
286287 }
287288
@@ -294,13 +295,16 @@ protected static function getValueNode(string $tagName, string $tagComment): Php
294295 {
295296 static $ phpDocParser ;
296297 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 );
299302 }
300303
301304 static $ phpDocLexer ;
302305 if (!$ phpDocLexer ) {
303- $ phpDocLexer = new Lexer ();
306+ $ config = new ParserConfig (usedAttributes: ['lines ' => true , 'indexes ' => true ]);
307+ $ phpDocLexer = new Lexer ($ config );
304308 }
305309
306310 return $ phpDocParser ->parseTagValue (new TokenIterator ($ phpDocLexer ->tokenize ($ tagComment )), $ tagName );
0 commit comments