Skip to content

Commit c13af9d

Browse files
committed
Initialize tokenKindToText when DiagnosticsProvider is loaded
1 parent f583f4c commit c13af9d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/DiagnosticsProvider.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,24 @@
1010

1111
class DiagnosticsProvider {
1212

13+
/**
14+
* @var string[] maps the token kind to the corresponding name
15+
*/
1316
private static $tokenKindToText;
1417

1518
/**
1619
* @param int $kind (must be a valid token kind)
1720
* @return string
1821
*/
1922
public static function getTextForTokenKind($kind) {
20-
if (!isset(self::$tokenKindToText)) {
21-
self::initTokenKindToText();
22-
}
2323
return self::$tokenKindToText[$kind];
2424
}
2525

2626
/**
27-
* @return string[]
27+
* This is called when this class is loaded, at the bottom of this file.
28+
* @return void
2829
*/
29-
private static function initTokenKindToText() {
30+
public static function initTokenKindToText() {
3031
self::$tokenKindToText = \array_flip(\array_merge(
3132
TokenStringMaps::OPERATORS_AND_PUNCTUATORS,
3233
TokenStringMaps::KEYWORDS,
@@ -58,9 +59,6 @@ public static function checkDiagnostics($node) {
5859
* @return Diagnostic|null
5960
*/
6061
private static function checkDiagnosticForUnexpectedToken($token) {
61-
if (!isset(self::$tokenKindToText)) {
62-
self::initTokenKindToText();
63-
}
6462
if ($token instanceof SkippedToken) {
6563
// TODO - consider also attaching parse context information to skipped tokens
6664
// this would allow us to provide more helpful error messages that inform users what to do
@@ -107,3 +105,5 @@ public static function getDiagnostics(Node $n) : array {
107105
return $diagnostics;
108106
}
109107
}
108+
109+
DiagnosticsProvider::initTokenKindToText();

0 commit comments

Comments
 (0)