Skip to content

Commit 2be11eb

Browse files
committed
Modernize: Tokenizer: use class constant for constant array
1 parent 7526ead commit 2be11eb

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/Tokenizers/Tokenizer.php

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,29 @@
1818
abstract class Tokenizer
1919
{
2020

21+
/**
22+
* List of tokens which may contain tab characters.
23+
*
24+
* @var array<int|string, true>
25+
*/
26+
private const TOKENS_WITH_TABS = [
27+
T_WHITESPACE => true,
28+
T_COMMENT => true,
29+
T_DOC_COMMENT => true,
30+
T_DOC_COMMENT_WHITESPACE => true,
31+
T_DOC_COMMENT_STRING => true,
32+
T_CONSTANT_ENCAPSED_STRING => true,
33+
T_DOUBLE_QUOTED_STRING => true,
34+
T_START_HEREDOC => true,
35+
T_START_NOWDOC => true,
36+
T_HEREDOC => true,
37+
T_NOWDOC => true,
38+
T_END_HEREDOC => true,
39+
T_END_NOWDOC => true,
40+
T_INLINE_HTML => true,
41+
T_YIELD_FROM => true,
42+
];
43+
2144
/**
2245
* The config data for the run.
2346
*
@@ -188,24 +211,6 @@ private function createPositionMap()
188211
$encoding = $this->config->encoding;
189212
$tabWidth = $this->config->tabWidth;
190213

191-
$tokensWithTabs = [
192-
T_WHITESPACE => true,
193-
T_COMMENT => true,
194-
T_DOC_COMMENT => true,
195-
T_DOC_COMMENT_WHITESPACE => true,
196-
T_DOC_COMMENT_STRING => true,
197-
T_CONSTANT_ENCAPSED_STRING => true,
198-
T_DOUBLE_QUOTED_STRING => true,
199-
T_START_HEREDOC => true,
200-
T_START_NOWDOC => true,
201-
T_HEREDOC => true,
202-
T_NOWDOC => true,
203-
T_END_HEREDOC => true,
204-
T_END_NOWDOC => true,
205-
T_INLINE_HTML => true,
206-
T_YIELD_FROM => true,
207-
];
208-
209214
$this->numTokens = count($this->tokens);
210215
for ($i = 0; $i < $this->numTokens; $i++) {
211216
$this->tokens[$i]['line'] = $lineNumber;
@@ -216,7 +221,7 @@ private function createPositionMap()
216221
$length = $this->knownLengths[$this->tokens[$i]['code']];
217222
$currColumn += $length;
218223
} else if ($tabWidth === 0
219-
|| isset($tokensWithTabs[$this->tokens[$i]['code']]) === false
224+
|| isset(self::TOKENS_WITH_TABS[$this->tokens[$i]['code']]) === false
220225
|| strpos($this->tokens[$i]['content'], "\t") === false
221226
) {
222227
// There are no tabs in this content, or we aren't replacing them.

0 commit comments

Comments
 (0)