Skip to content

Commit 13311ae

Browse files
committed
PHPCS 4.x: let T_STATIC be T_STATIC
Implementation of the proposal outlined in issue 3115. 1. Removes the Tokenizer/PHP code which made an exception for `instanceof static`. 2. Adds an exception for `instanceof static` to the `Squiz.WhiteSpace.ScopeKeywordSpacing` sniff for which the tokenizer code was originally put in place. The tests for all other sniffs still pass. I've had a quick look through the other sniffs which refer to the `T_STATIC` token, but didn't see any which should be impacted by this change (and didn't have unit tests with `instanceof static`). Fixes 3115
1 parent 80ef63b commit 13311ae

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

src/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public function process(File $phpcsFile, $stackPtr)
5353

5454
if ($tokens[$stackPtr]['code'] === T_STATIC
5555
&& (($nextToken === false || $tokens[$nextToken]['code'] === T_DOUBLE_COLON)
56-
|| $tokens[$prevToken]['code'] === T_NEW)
56+
|| $tokens[$prevToken]['code'] === T_NEW
57+
|| $tokens[$prevToken]['code'] === T_INSTANCEOF)
5758
) {
5859
// Late static binding, e.g., static:: OR new static() usage or live coding.
5960
return;

src/Tokenizers/PHP.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,24 +1892,6 @@ protected function processAdditional()
18921892
}
18931893
}
18941894

1895-
continue;
1896-
} else if ($this->tokens[$i]['code'] === T_STATIC) {
1897-
for ($x = ($i - 1); $x > 0; $x--) {
1898-
if (isset(Tokens::$emptyTokens[$this->tokens[$x]['code']]) === false) {
1899-
break;
1900-
}
1901-
}
1902-
1903-
if ($this->tokens[$x]['code'] === T_INSTANCEOF) {
1904-
$this->tokens[$i]['code'] = T_STRING;
1905-
$this->tokens[$i]['type'] = 'T_STRING';
1906-
1907-
if (PHP_CODESNIFFER_VERBOSITY > 1) {
1908-
$line = $this->tokens[$i]['line'];
1909-
Common::printStatusMessage("* token $i on line $line changed from T_STATIC to T_STRING", 1);
1910-
}
1911-
}
1912-
19131895
continue;
19141896
} else if ($this->tokens[$i]['code'] === T_TRUE
19151897
|| $this->tokens[$i]['code'] === T_FALSE

0 commit comments

Comments
 (0)