Skip to content

Commit

Permalink
4.0 | Let T_STATIC be T_STATIC
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jrfnl committed Dec 6, 2023
1 parent 8b5e6e9 commit e8d665c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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;
Expand Down
18 changes: 0 additions & 18 deletions src/Tokenizers/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -2940,24 +2940,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
Expand Down

0 comments on commit e8d665c

Please sign in to comment.