From 2f9784281daae3c5c513c7a57708bd78f97d0ad5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 21 Sep 2020 23:29:38 +0200 Subject: [PATCH] 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 --- .../WhiteSpace/ScopeKeywordSpacingSniff.php | 1 + src/Tokenizers/PHP.php | 18 ------------------ 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php b/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php index de92697db0..7968332bf6 100644 --- a/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php +++ b/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php @@ -54,6 +54,7 @@ public function process(File $phpcsFile, $stackPtr) if ($tokens[$stackPtr]['code'] === T_STATIC) { if (($nextToken === false || $tokens[$nextToken]['code'] === T_DOUBLE_COLON) || $tokens[$prevToken]['code'] === T_NEW + || $tokens[$prevToken]['code'] === T_INSTANCEOF ) { // Late static binding, e.g., static:: OR new static() usage or live coding. return; diff --git a/src/Tokenizers/PHP.php b/src/Tokenizers/PHP.php index 9201a43c9c..77a175cc97 100644 --- a/src/Tokenizers/PHP.php +++ b/src/Tokenizers/PHP.php @@ -2506,24 +2506,6 @@ protected function processAdditional() } } - continue; - } else if ($this->tokens[$i]['code'] === T_STATIC) { - for ($x = ($i - 1); $x > 0; $x--) { - if (isset(Tokens::$emptyTokens[$this->tokens[$x]['code']]) === false) { - break; - } - } - - if ($this->tokens[$x]['code'] === T_INSTANCEOF) { - $this->tokens[$i]['code'] = T_STRING; - $this->tokens[$i]['type'] = 'T_STRING'; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $line = $this->tokens[$i]['line']; - Common::printStatusMessage("* token $i on line $line changed from T_STATIC to T_STRING", 1); - } - } - continue; } else if ($this->tokens[$i]['code'] === T_TRUE || $this->tokens[$i]['code'] === T_FALSE