File tree Expand file tree Collapse file tree 2 files changed +66
-19
lines changed Expand file tree Collapse file tree 2 files changed +66
-19
lines changed Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \PhpDocParser \Ast \PhpDoc ;
4+
5+
6+ use PHPStan \PhpDocParser \Parser \ParserException ;
7+
8+
9+ class InvalidTagValueNode implements PhpDocTagValueNode
10+ {
11+ /** @var string (may be empty) */
12+ public $ value ;
13+
14+ /** @var ParserException */
15+ public $ exception ;
16+
17+
18+ public function __construct (string $ value , ParserException $ exception )
19+ {
20+ $ this ->value = $ value ;
21+ $ this ->exception = $ exception ;
22+ }
23+
24+
25+ public function __toString (): string
26+ {
27+ return $ this ->value ;
28+ }
29+ }
Original file line number Diff line number Diff line change @@ -61,28 +61,46 @@ public function parseTag(TokenIterator $tokens): Ast\PhpDoc\PhpDocTagNode
6161
6262 private function parseTagValue (TokenIterator $ tokens , string $ tag ): Ast \PhpDoc \PhpDocTagValueNode
6363 {
64- switch ($ tag ) {
65- case '@param ' :
66- return $ this ->parseParamTagValue ($ tokens );
67-
68- case '@var ' :
69- return $ this ->parseVarTagValue ($ tokens );
70-
71- case '@return ' :
72- case '@returns ' :
73- return $ this ->parseReturnTagValue ($ tokens );
74-
75- case '@property ' :
76- case '@property-read ' :
77- case '@property-write ' :
78- return $ this ->parsePropertyTagValue ($ tokens );
64+ try {
65+ $ tokens ->pushSavePoint ();
66+
67+ switch ($ tag ) {
68+ case '@param ' :
69+ $ tagValue = $ this ->parseParamTagValue ($ tokens );
70+ break ;
71+
72+ case '@var ' :
73+ $ tagValue = $ this ->parseVarTagValue ($ tokens );
74+ break ;
75+
76+ case '@return ' :
77+ case '@returns ' :
78+ $ tagValue = $ this ->parseReturnTagValue ($ tokens );
79+ break ;
80+
81+ case '@property ' :
82+ case '@property-read ' :
83+ case '@property-write ' :
84+ $ tagValue = $ this ->parsePropertyTagValue ($ tokens );
85+ break ;
86+
87+ case '@method ' :
88+ $ tagValue = $ this ->parseMethodTagValue ($ tokens );
89+ break ;
90+
91+ default :
92+ $ tagValue = new Ast \PhpDoc \GenericTagValueNode ($ this ->parseOptionalDescription ($ tokens ));
93+ break ;
94+ }
7995
80- case '@method ' :
81- return $ this ->parseMethodTagValue ($ tokens );
96+ $ tokens ->dropSavePoint ();
8297
83- default :
84- return new Ast \PhpDoc \GenericTagValueNode ($ this ->parseOptionalDescription ($ tokens ));
98+ } catch (ParserException $ e ) {
99+ $ tokens ->rollback ();
100+ $ tagValue = new Ast \PhpDoc \InvalidTagValueNode ($ this ->parseOptionalDescription ($ tokens ), $ e );
85101 }
102+
103+ return $ tagValue ;
86104 }
87105
88106
You can’t perform that action at this time.
0 commit comments