Skip to content

Commit 77b2588

Browse files
committed
verify
1 parent 3f0f728 commit 77b2588

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

phpstan-baseline.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ parameters:
2929
identifier: property.dynamicName
3030
count: 2
3131
path: src/Printer/Printer.php
32+
33+
-
34+
message: '#^Variable property access on PHPStan\\PhpDocParser\\Ast\\Node\.$#'
35+
identifier: property.dynamicName
36+
count: 1
37+
path: tests/PHPStan/Parser/TypeParserTest.php

tests/PHPStan/Parser/TypeParserTest.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function testVerifyAttributes(string $input, $expectedResult): void
140140
$this->assertNotNull($node->getAttribute(Attribute::END_INDEX), (string) $node);
141141
}
142142

143-
$this->verifyNodeIndexes($node);
143+
$this->verifyNodeIndexes($typeNode);
144144

145145
$this->assertEquals(
146146
$this->unsetAllAttributesButComments($expectedResult),
@@ -151,19 +151,30 @@ public function testVerifyAttributes(string $input, $expectedResult): void
151151

152152
private function verifyNodeIndexes(Node $node): void
153153
{
154+
$startIndex = $node->getAttribute(Attribute::START_INDEX);
155+
$endIndex = $node->getAttribute(Attribute::END_INDEX);
156+
$comments = $node->getAttribute(Attribute::COMMENTS) ?? [];
157+
foreach ($comments as $comment) {
158+
$this->assertGreaterThanOrEqual($startIndex, $comment->getAttribute(Attribute::START_INDEX));
159+
$this->assertLessThanOrEqual($endIndex, $comment->getAttribute(Attribute::END_INDEX));
160+
}
161+
154162
$subNodeNames = array_keys(get_object_vars($node));
155163
foreach ($subNodeNames as $subNodeName) {
156164
$subNode = $node->$subNodeName;
157165
if (is_array($subNode)) {
158166
$lastEndIndex = null;
159167
foreach ($subNode as $subSubNode) {
160-
$startIndex = $subSubNode->getAttribute(Attribute::START_INDEX);
161-
$endIndex = $subSubNode->getAttribute(Attribute::END_INDEX);
168+
if (!$subSubNode instanceof Node) {
169+
continue;
170+
}
171+
172+
$subStartIndex = $subSubNode->getAttribute(Attribute::START_INDEX);
162173
if ($lastEndIndex !== null) {
163-
$this->assertGreaterThan($startIndex, $lastEndIndex, (string) $subSubNode);
174+
$this->assertGreaterThan($lastEndIndex, $subStartIndex, (string) $subSubNode);
164175
}
165176

166-
$lastEndIndex = $endIndex;
177+
$lastEndIndex = $subSubNode->getAttribute(Attribute::END_INDEX);
167178

168179
$this->verifyNodeIndexes($subSubNode);
169180
}

0 commit comments

Comments
 (0)