File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
4949 $ type = $ this ->parseGeneric ($ tokens , $ type );
5050
5151 } elseif ($ tokens ->isCurrentTokenType (Lexer::TOKEN_OPEN_PARENTHESES )) {
52- $ type = $ this ->parseCallable ($ tokens , $ type );
52+ $ type = $ this ->tryParseCallable ($ tokens , $ type );
5353
5454 } elseif ($ tokens ->isCurrentTokenType (Lexer::TOKEN_OPEN_SQUARE_BRACKET )) {
5555 $ type = $ this ->tryParseArray ($ tokens , $ type );
@@ -174,6 +174,22 @@ private function parseCallableReturnType(TokenIterator $tokens): Ast\Type\TypeNo
174174 }
175175
176176
177+ private function tryParseCallable (TokenIterator $ tokens , Ast \Type \IdentifierTypeNode $ identifier ): Ast \Type \TypeNode
178+ {
179+ try {
180+ $ tokens ->pushSavePoint ();
181+ $ type = $ this ->parseCallable ($ tokens , $ identifier );
182+ $ tokens ->dropSavePoint ();
183+
184+ } catch (\PHPStan \PhpDocParser \Parser \ParserException $ e ) {
185+ $ tokens ->rollback ();
186+ $ type = $ identifier ;
187+ }
188+
189+ return $ type ;
190+ }
191+
192+
177193 private function tryParseArray (TokenIterator $ tokens , Ast \Type \TypeNode $ type ): Ast \Type \TypeNode
178194 {
179195 try {
Original file line number Diff line number Diff line change @@ -377,6 +377,21 @@ public function provideVarTagsData(): \Iterator
377377 ]),
378378 ];
379379
380+ yield [
381+ 'OK without variable name and description in parentheses ' ,
382+ '/** @var Foo (Bar) */ ' ,
383+ new PhpDocNode ([
384+ new PhpDocTagNode (
385+ '@var ' ,
386+ new VarTagValueNode (
387+ new IdentifierTypeNode ('Foo ' ),
388+ '' ,
389+ '(Bar) '
390+ )
391+ ),
392+ ]),
393+ ];
394+
380395 yield [
381396 'OK with variable name and description ' ,
382397 '/** @var Foo $foo optional description */ ' ,
You can’t perform that action at this time.
0 commit comments