Skip to content

Commit c644756

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 6f78d8c commit c644756

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
@@ -2184,24 +2184,6 @@ protected function processAdditional()
21842184
}
21852185
}
21862186

2187-
continue;
2188-
} else if ($this->tokens[$i]['code'] === T_STATIC) {
2189-
for ($x = ($i - 1); $x > 0; $x--) {
2190-
if (isset(Tokens::$emptyTokens[$this->tokens[$x]['code']]) === false) {
2191-
break;
2192-
}
2193-
}
2194-
2195-
if ($this->tokens[$x]['code'] === T_INSTANCEOF) {
2196-
$this->tokens[$i]['code'] = T_STRING;
2197-
$this->tokens[$i]['type'] = 'T_STRING';
2198-
2199-
if (PHP_CODESNIFFER_VERBOSITY > 1) {
2200-
$line = $this->tokens[$i]['line'];
2201-
Common::printStatusMessage("* token $i on line $line changed from T_STATIC to T_STRING", 1);
2202-
}
2203-
}
2204-
22052187
continue;
22062188
} else if ($this->tokens[$i]['code'] === T_TRUE
22072189
|| $this->tokens[$i]['code'] === T_FALSE

0 commit comments

Comments
 (0)