88
99use Microsoft \PhpParser \Node ;
1010
11- class Utilities {
11+ class Diagnostics {
1212 public static function getDiagnostics ($ node ) {
13- $ tokenKindToText = array_flip (array_merge (
13+ $ tokenKindToText = \ array_flip (\ array_merge (
1414 TokenStringMaps::OPERATORS_AND_PUNCTUATORS ,
1515 TokenStringMaps::KEYWORDS ,
1616 TokenStringMaps::RESERVED_WORDS
@@ -63,52 +63,7 @@ public static function getDiagnostics($node) {
6363 }
6464
6565 foreach ($ node ->getChildNodesAndTokens () as $ child ) {
66- yield from Utilities ::getDiagnostics ($ child );
66+ yield from Diagnostics ::getDiagnostics ($ child );
6767 }
6868 }
69-
70- public static function getRangeFromPosition ($ pos , $ length , $ text ) {
71- $ start = self ::getLineCharacterPositionFromPosition ($ pos , $ text );
72- $ end = self ::getLineCharacterPositionFromPosition ($ pos + $ length , $ text );
73-
74- return new Range ($ start , $ end );
75- }
76-
77- public static function getLineCharacterPositionFromPosition ($ pos , $ text ) : LineCharacterPosition {
78- $ newlinePositions = [];
79- $ newlinePos = -1 ;
80- while ($ newlinePos = strpos ($ text , "\n" , $ newlinePos + 1 )) {
81- if ($ newlinePos < $ pos ) {
82- $ newlinePositions [] = $ newlinePos ;
83- continue ;
84- }
85- break ;
86- }
87-
88- $ lastNewline = count ($ newlinePositions ) - 1 ;
89- $ char = $ pos - ($ lastNewline >= 0 ? $ newlinePositions [$ lastNewline ] + 1 : 0 );
90- $ line = count ($ newlinePositions );
91-
92- return new LineCharacterPosition ($ line , $ char );
93- }
94- }
95-
96- class Range {
97- public $ start ;
98- public $ end ;
99-
100- public function __construct (LineCharacterPosition $ start , LineCharacterPosition $ end ) {
101- $ this ->start = $ start ;
102- $ this ->end = $ end ;
103- }
104- }
105-
106- class LineCharacterPosition {
107- public $ line ;
108- public $ character ;
109-
110- public function __construct (int $ line , int $ character ) {
111- $ this ->line = $ line ;
112- $ this ->character = $ character ;
113- }
11469}
0 commit comments