Skip to content

Commit 46983c7

Browse files
committed
Fixed bug #1421 : Ternaries used in constant scalar expression for param default misidentified by tokenizer
1 parent 0608ac8 commit 46983c7

File tree

5 files changed

+7
-1
lines changed

5 files changed

+7
-1
lines changed

CodeSniffer/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,5 @@ $username = $_GET['user']??'nobody';
187187
function foo(string $bar, array $baz, ?MyClass $object) : MyClass {}
188188

189189
declare(strict_types=1);
190+
191+
function foo($c = ((BAR)?10:100)) {}

CodeSniffer/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,5 @@ $username = $_GET['user'] ?? 'nobody';
181181
function foo(string $bar, array $baz, ?MyClass $object) : MyClass {}
182182

183183
declare(strict_types=1);
184+
185+
function foo($c = ((BAR) ? 10 : 100)) {}

CodeSniffer/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public function getErrorList($testFile='OperatorSpacingUnitTest.inc')
104104
178 => 1,
105105
179 => 1,
106106
185 => 2,
107+
191 => 4,
107108
);
108109
break;
109110
case 'OperatorSpacingUnitTest.js':

CodeSniffer/Tokenizers/PHP.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ public function tokenizeString($string, $eolChar='\n')
733733
$newToken['code'] = T_NULLABLE;
734734
$newToken['type'] = 'T_NULLABLE';
735735
break;
736-
} else if (in_array($tokenType, array(T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, '{', ';')) === true) {
736+
} else if (in_array($tokenType, array(T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, '=', '{', ';')) === true) {
737737
$newToken['code'] = T_INLINE_THEN;
738738
$newToken['type'] = 'T_INLINE_THEN';
739739

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
5757
- Fixed bug #1394 : integer type hints appearing as TypeHintMissing instead of ScalarTypeHintMissing
5858
-- PHP 7 type hints were also being shown when run under PHP 5 in some cases
5959
- Fixed bug #1405 : Squiz.WhiteSpace.ScopeClosingBrace fails to fix closing brace within indented PHP tags
60+
- Fixed bug #1421 : Ternaries used in constant scalar expression for param default misidentified by tokenizer
6061
</notes>
6162
<contents>
6263
<dir name="/">

0 commit comments

Comments
 (0)