@@ -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