Skip to content

Commit 8e57c25

Browse files
committed
PHPCSDebug/TokenList: bug fix - do not calculate token length
The output from the `TokenList` sniff should represent the information contained within the `$tokens` array. While the information in the `$tokens` array may not be correct, the sniff should not try to "fix" it as that will misrepresent the real information contained in the `$tokens` array. To this end: * Ensure there is always a `'length'` key available by adding it to the `$tokenDefaults` array. * Remove any manipulation of the value of the token `length` index.
1 parent 3abedb7 commit 8e57c25

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

PHPCSDebug/Sniffs/Debug/TokenListSniff.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class TokenListSniff implements Sniff
4747
'type' => '?',
4848
'code' => '?',
4949
'content' => '',
50+
'length' => '?',
5051
'line' => '?',
5152
'column' => '?',
5253
'level' => 0,
@@ -99,13 +100,6 @@ public function process(File $phpcsFile, $stackPtr)
99100
$token += $this->tokenDefaults;
100101
$content = $token['content'];
101102

102-
if (isset($token['length']) === false) {
103-
$token['length'] = 0;
104-
if (isset($token['content'])) {
105-
$token['length'] = \strlen($content);
106-
}
107-
}
108-
109103
if (isset($token['orig_content'])) {
110104
$content = $this->visualizeWhitespace($content);
111105
$content .= $sep . 'Orig: ' . $this->visualizeWhitespace($token['orig_content']);

0 commit comments

Comments
 (0)