@@ -140,7 +140,7 @@ public function testVerifyAttributes(string $input, $expectedResult): void
140
140
$ this ->assertNotNull ($ node ->getAttribute (Attribute::END_INDEX ), (string ) $ node );
141
141
}
142
142
143
- $ this ->verifyNodeIndexes ($ node );
143
+ $ this ->verifyNodeIndexes ($ typeNode );
144
144
145
145
$ this ->assertEquals (
146
146
$ this ->unsetAllAttributesButComments ($ expectedResult ),
@@ -151,19 +151,30 @@ public function testVerifyAttributes(string $input, $expectedResult): void
151
151
152
152
private function verifyNodeIndexes (Node $ node ): void
153
153
{
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
+
154
162
$ subNodeNames = array_keys (get_object_vars ($ node ));
155
163
foreach ($ subNodeNames as $ subNodeName ) {
156
164
$ subNode = $ node ->$ subNodeName ;
157
165
if (is_array ($ subNode )) {
158
166
$ lastEndIndex = null ;
159
167
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 );
162
173
if ($ lastEndIndex !== null ) {
163
- $ this ->assertGreaterThan ($ startIndex , $ lastEndIndex , (string ) $ subSubNode );
174
+ $ this ->assertGreaterThan ($ lastEndIndex , $ subStartIndex , (string ) $ subSubNode );
164
175
}
165
176
166
- $ lastEndIndex = $ endIndex ;
177
+ $ lastEndIndex = $ subSubNode -> getAttribute (Attribute:: END_INDEX ) ;
167
178
168
179
$ this ->verifyNodeIndexes ($ subSubNode );
169
180
}
0 commit comments