We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d789c95 commit a61e41dCopy full SHA for a61e41d
src/Parser/ConstExprParser.php
@@ -245,22 +245,14 @@ private function parseArrayItem(TokenIterator $tokens): Ast\ConstExpr\ConstExprA
245
*/
246
private function enrichWithAttributes(TokenIterator $tokens, Ast\ConstExpr\ConstExprNode $node, int $startLine, int $startIndex): Ast\ConstExpr\ConstExprNode
247
{
248
- $endLine = $tokens->currentTokenLine();
249
- $endIndex = $tokens->currentTokenIndex();
250
if ($this->useLinesAttributes) {
251
$node->setAttribute(Ast\Attribute::START_LINE, $startLine);
252
- $node->setAttribute(Ast\Attribute::END_LINE, $endLine);
+ $node->setAttribute(Ast\Attribute::END_LINE, $tokens->currentTokenLine());
253
}
254
255
if ($this->useIndexAttributes) {
256
- $tokensArray = $tokens->getTokens();
257
- $endIndex--;
258
- if ($tokensArray[$endIndex][Lexer::TYPE_OFFSET] === Lexer::TOKEN_HORIZONTAL_WS) {
259
260
- }
261
-
262
$node->setAttribute(Ast\Attribute::START_INDEX, $startIndex);
263
- $node->setAttribute(Ast\Attribute::END_INDEX, $endIndex);
+ $node->setAttribute(Ast\Attribute::END_INDEX, $tokens->endIndexOfLastRelevantToken());
264
265
266
return $node;
src/Parser/PhpDocParser.php
@@ -161,23 +161,14 @@ private function parseChild(TokenIterator $tokens): Ast\PhpDoc\PhpDocChildNode
161
162
private function enrichWithAttributes(TokenIterator $tokens, Ast\Node $tag, int $startLine, int $startIndex): Ast\Node
163
164
165
166
167
168
$tag->setAttribute(Ast\Attribute::START_LINE, $startLine);
169
- $tag->setAttribute(Ast\Attribute::END_LINE, $endLine);
+ $tag->setAttribute(Ast\Attribute::END_LINE, $tokens->currentTokenLine());
170
171
172
173
174
175
176
177
178
179
$tag->setAttribute(Ast\Attribute::START_INDEX, $startIndex);
180
- $tag->setAttribute(Ast\Attribute::END_INDEX, $endIndex);
+ $tag->setAttribute(Ast\Attribute::END_INDEX, $tokens->endIndexOfLastRelevantToken());
181
182
183
return $tag;
src/Parser/TokenIterator.php
@@ -102,6 +102,21 @@ public function currentTokenIndex(): int
102
103
104
105
+ public function endIndexOfLastRelevantToken(): int
106
+ {
107
+ $endIndex = $this->currentTokenIndex();
108
+ $endIndex--;
109
+ while (in_array($this->tokens[$endIndex][Lexer::TYPE_OFFSET], $this->skippedTokenTypes, true)) {
110
+ if (!isset($this->tokens[$endIndex - 1])) {
111
+ break;
112
+ }
113
114
115
+
116
+ return $endIndex;
117
118
119
120
public function isCurrentTokenValue(string $tokenValue): bool
121
122
return $this->tokens[$this->index][Lexer::VALUE_OFFSET] === $tokenValue;
src/Parser/TypeParser.php
@@ -70,23 +70,14 @@ public function parse(TokenIterator $tokens): Ast\Type\TypeNode
70
71
public function enrichWithAttributes(TokenIterator $tokens, Ast\Node $type, int $startLine, int $startIndex): Ast\Node
72
73
74
75
76
77
$type->setAttribute(Ast\Attribute::START_LINE, $startLine);
78
- $type->setAttribute(Ast\Attribute::END_LINE, $endLine);
+ $type->setAttribute(Ast\Attribute::END_LINE, $tokens->currentTokenLine());
79
80
81
82
83
84
85
86
87
88
$type->setAttribute(Ast\Attribute::START_INDEX, $startIndex);
89
- $type->setAttribute(Ast\Attribute::END_INDEX, $endIndex);
+ $type->setAttribute(Ast\Attribute::END_INDEX, $tokens->endIndexOfLastRelevantToken());
90
91
92
return $type;
tests/PHPStan/Parser/PhpDocParserTest.php
@@ -5970,12 +5970,12 @@ public function dataDeepNodesLinesAndIndexes(): iterable
5970
[2, 8, 2, 23], // PhpDocTagNode
5971
[2, 8, 3, 23], // DoctrineTagValueNode
5972
[2, 8, 3, 23], // DoctrineAnnotation
5973
- [2, 8, 4, 22], // DoctrineArgument
5974
- [2, 8, 4, 22], // DoctrineArray
+ [2, 8, 4, 21], // DoctrineArgument
+ [2, 8, 4, 21], // DoctrineArray
5975
[3, 3, 7, 7], // DoctrineArrayItem
5976
[3, 3, 7, 7], // ConstExprIntegerNode
5977
- [4, 5, 11, 12], // DoctrineArrayItem
5978
- [4, 5, 11, 12], // ConstExprIntegerNode
+ [4, 5, 11, 11], // DoctrineArrayItem
+ [4, 5, 11, 11], // ConstExprIntegerNode
5979
[6, 6, 18, 18], // DoctrineArrayItem
5980
[6, 6, 18, 18], // ConstExprIntegerNode
5981
],
0 commit comments