|
10 | 10 | use VariableAnalysis\Lib\ScopeType; |
11 | 11 | use VariableAnalysis\Lib\VariableInfo; |
12 | 12 | use PHP_CodeSniffer\Util\Tokens; |
| 13 | +use PHPCSUtils\Utils\Context; |
13 | 14 |
|
14 | 15 | class Helpers |
15 | 16 | { |
@@ -1333,22 +1334,8 @@ public static function getFunctionIndexForFunctionCallArgument(File $phpcsFile, |
1333 | 1334 | */ |
1334 | 1335 | public static function isVariableInsideIssetOrEmpty(File $phpcsFile, $stackPtr) |
1335 | 1336 | { |
1336 | | - $functionIndex = self::getFunctionIndexForFunctionCallArgument($phpcsFile, $stackPtr); |
1337 | | - if (! is_int($functionIndex)) { |
1338 | | - return false; |
1339 | | - } |
1340 | | - $tokens = $phpcsFile->getTokens(); |
1341 | | - if (! isset($tokens[$functionIndex])) { |
1342 | | - return false; |
1343 | | - } |
1344 | | - $allowedFunctionNames = [ |
1345 | | - 'isset', |
1346 | | - 'empty', |
1347 | | - ]; |
1348 | | - if (in_array($tokens[$functionIndex]['content'], $allowedFunctionNames, true)) { |
1349 | | - return true; |
1350 | | - } |
1351 | | - return false; |
| 1337 | + // Use PHPCSUtils which handles all edge cases across PHP/PHPCS versions |
| 1338 | + return Context::inIsset($phpcsFile, $stackPtr) || Context::inEmpty($phpcsFile, $stackPtr); |
1352 | 1339 | } |
1353 | 1340 |
|
1354 | 1341 | /** |
@@ -1397,18 +1384,8 @@ public static function isVariableArrayPushShortcut(File $phpcsFile, $stackPtr) |
1397 | 1384 | */ |
1398 | 1385 | public static function isVariableInsideUnset(File $phpcsFile, $stackPtr) |
1399 | 1386 | { |
1400 | | - $functionIndex = self::getFunctionIndexForFunctionCallArgument($phpcsFile, $stackPtr); |
1401 | | - if (! is_int($functionIndex)) { |
1402 | | - return false; |
1403 | | - } |
1404 | | - $tokens = $phpcsFile->getTokens(); |
1405 | | - if (! isset($tokens[$functionIndex])) { |
1406 | | - return false; |
1407 | | - } |
1408 | | - if ($tokens[$functionIndex]['content'] === 'unset') { |
1409 | | - return true; |
1410 | | - } |
1411 | | - return false; |
| 1387 | + // Use PHPCSUtils which handles all edge cases across PHP/PHPCS versions |
| 1388 | + return Context::inUnset($phpcsFile, $stackPtr); |
1412 | 1389 | } |
1413 | 1390 |
|
1414 | 1391 | /** |
|
0 commit comments