Skip to content

Commit 2166fe8

Browse files
committed
Merge branch 'master' into 3.0
2 parents dda854f + 531a731 commit 2166fe8

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,13 @@ switch($foo)
144144
break;
145145
}
146146
}
147+
148+
switch ($foo) {
149+
case Foo::INTERFACE:
150+
return self::INTERFACE;
151+
case Foo::NAMESPACE:
152+
return self::MODULE;
153+
case Foo::TRAIT:
154+
case Foo::ARRAY:
155+
return self::VALUE;
156+
}

src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.inc.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,13 @@ switch($foo)
147147
break;
148148
}
149149
}
150+
151+
switch ($foo) {
152+
case Foo::INTERFACE:
153+
return self::INTERFACE;
154+
case Foo::NAMESPACE:
155+
return self::MODULE;
156+
case Foo::TRAIT:
157+
case Foo::ARRAY:
158+
return self::VALUE;
159+
}

src/Tokenizers/PHP.php

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,30 @@ protected function tokenize($string)
810810
continue;
811811
}
812812

813+
/*
814+
Tokens after a double colon may be look like scope openers,
815+
such as when writing code like Foo::NAMESAPCE, but they are
816+
only ever variables or strings.
817+
*/
818+
819+
if ($stackPtr > 1
820+
&& $tokens[($stackPtr - 1)][0] === T_PAAMAYIM_NEKUDOTAYIM
821+
&& $tokenIsArray === true
822+
&& $token[0] !== T_STRING
823+
&& $token[0] !== T_VARIABLE
824+
&& $token[0] !== T_DOLLAR
825+
&& isset(Util\Tokens::$emptyTokens[$token[0]]) === false
826+
) {
827+
$newToken = array();
828+
$newToken['code'] = T_STRING;
829+
$newToken['type'] = 'T_STRING';
830+
$newToken['content'] = $token[1];
831+
$finalTokens[$newStackPtr] = $newToken;
832+
833+
$newStackPtr++;
834+
continue;
835+
}
836+
813837
/*
814838
Before PHP 7, the <=> operator was tokenized as
815839
T_IS_SMALLER_OR_EQUAL followed by T_GREATER_THAN.
@@ -1398,25 +1422,6 @@ protected function processAdditional()
13981422
echo "\t* token $x on line $line changed from $type to T_STRING".PHP_EOL;
13991423
}
14001424

1401-
$this->tokens[$x]['code'] = T_STRING;
1402-
$this->tokens[$x]['type'] = 'T_STRING';
1403-
}
1404-
} else if ($this->tokens[$i]['code'] === T_PAAMAYIM_NEKUDOTAYIM) {
1405-
// Context sensitive keywords support.
1406-
for ($x = ($i + 1); $i < $numTokens; $x++) {
1407-
if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]) === false) {
1408-
// Non-whitespace content.
1409-
break;
1410-
}
1411-
}
1412-
1413-
if (in_array($this->tokens[$x]['code'], array(T_STRING, T_VARIABLE, T_DOLLAR), true) === false) {
1414-
if (PHP_CODESNIFFER_VERBOSITY > 1) {
1415-
$line = $this->tokens[$x]['line'];
1416-
$type = $this->tokens[$x]['type'];
1417-
echo "\t* token $x on line $line changed from $type to T_STRING".PHP_EOL;
1418-
}
1419-
14201425
$this->tokens[$x]['code'] = T_STRING;
14211426
$this->tokens[$x]['type'] = 'T_STRING';
14221427
}

0 commit comments

Comments
 (0)