Skip to content

Commit 95daae9

Browse files
authored
Merge pull request #1226 from PHPCSStandards/phpcs-4.x/feature/fix-another-php-8.5-runtime-deprecation
PHP 8.5 | Fix another runtime deprecation notice
2 parents 644978d + 03e1866 commit 95daae9

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/Tokenizers/PHP.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,15 +2139,25 @@ protected function tokenize($string)
21392139
continue;
21402140
}
21412141

2142-
if (($tokenType !== T_CALLABLE
2143-
&& isset($lastRelevantNonEmpty) === false)
2144-
|| ($lastRelevantNonEmpty === T_ARRAY
2145-
&& $tokenType === '(')
2146-
|| (isset(Tokens::NAME_TOKENS[$lastRelevantNonEmpty]) === true
2147-
&& ($tokenType === T_DOUBLE_COLON
2148-
|| $tokenType === '('
2149-
|| $tokenType === ':'))
2150-
) {
2142+
$isInlineThen = false;
2143+
if (isset($lastRelevantNonEmpty) === false && $tokenType !== T_CALLABLE) {
2144+
// Can be anything, but is definitely not a type declaration.
2145+
$isInlineThen = true;
2146+
} else if (isset($lastRelevantNonEmpty) === true) {
2147+
if ($lastRelevantNonEmpty === T_ARRAY && $tokenType === '(') {
2148+
// Array declaration in ternary then.
2149+
$isInlineThen = true;
2150+
} else if (isset(Tokens::NAME_TOKENS[$lastRelevantNonEmpty]) === true
2151+
&& ($tokenType === T_DOUBLE_COLON
2152+
|| $tokenType === '('
2153+
|| $tokenType === ':')
2154+
) {
2155+
// Constant access, function call, static class member access in ternary then.
2156+
$isInlineThen = true;
2157+
}
2158+
}
2159+
2160+
if ($isInlineThen === true) {
21512161
if (PHP_CODESNIFFER_VERBOSITY > 1) {
21522162
StatusWriter::write("* token $stackPtr changed from ? to T_INLINE_THEN", 2);
21532163
}

0 commit comments

Comments
 (0)