Skip to content

Commit c46d135

Browse files
committed
Merge branch 'hotfix/2713-fn-closure-ternary-tokenizer' of https://github.com/michalbundyra/PHP_CodeSniffer
2 parents 5157a81 + 8e41312 commit c46d135

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/Standards/Squiz/Tests/PHP/DisallowInlineIfUnitTest.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ class Example {
1414
}
1515

1616
$a = fn(?\DateTime $x) : ?\DateTime => $x;
17+
18+
$b = fn ($b) => $b ? true : false;

src/Standards/Squiz/Tests/PHP/DisallowInlineIfUnitTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ public function getErrorList($testFile='DisallowInlineIfUnitTest.inc')
2929
{
3030
switch ($testFile) {
3131
case 'DisallowInlineIfUnitTest.inc':
32-
return [8 => 1];
32+
return [
33+
8 => 1,
34+
18 => 1,
35+
];
3336
break;
3437
case 'DisallowInlineIfUnitTest.js':
3538
return [1 => 1];

src/Tokenizers/PHP.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ protected function tokenize($string)
10831083
$newToken['code'] = T_NULLABLE;
10841084
$newToken['type'] = 'T_NULLABLE';
10851085
break;
1086-
} else if (in_array($tokenType, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, '=', '{', ';'], true) === true) {
1086+
} else if (in_array($tokenType, [T_DOUBLE_ARROW, T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, '=', '{', ';'], true) === true) {
10871087
if (PHP_CODESNIFFER_VERBOSITY > 1) {
10881088
echo "\t\t* token $stackPtr changed from ? to T_INLINE_THEN".PHP_EOL;
10891089
}
@@ -1486,7 +1486,7 @@ function return types. We want to keep the parenthesis map clean,
14861486
}
14871487
}
14881488

1489-
if ($tokens[$i][0] === T_FUNCTION || $tokens[$i][0] === T_USE) {
1489+
if ($tokens[$i][0] === T_FUNCTION || $tokens[$i][0] === T_FN || $tokens[$i][0] === T_USE) {
14901490
$isReturnType = true;
14911491
}
14921492
}//end if

0 commit comments

Comments
 (0)