Skip to content

Commit 6a30e89

Browse files
committed
Replace isVariableInsideUnset/isVariableInsideIssetOrEmpty
1 parent 7c4280b commit 6a30e89

1 file changed

Lines changed: 5 additions & 28 deletions

File tree

VariableAnalysis/Lib/Helpers.php

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use VariableAnalysis\Lib\ScopeType;
1111
use VariableAnalysis\Lib\VariableInfo;
1212
use PHP_CodeSniffer\Util\Tokens;
13+
use PHPCSUtils\Utils\Context;
1314

1415
class Helpers
1516
{
@@ -1333,22 +1334,8 @@ public static function getFunctionIndexForFunctionCallArgument(File $phpcsFile,
13331334
*/
13341335
public static function isVariableInsideIssetOrEmpty(File $phpcsFile, $stackPtr)
13351336
{
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);
13521339
}
13531340

13541341
/**
@@ -1397,18 +1384,8 @@ public static function isVariableArrayPushShortcut(File $phpcsFile, $stackPtr)
13971384
*/
13981385
public static function isVariableInsideUnset(File $phpcsFile, $stackPtr)
13991386
{
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);
14121389
}
14131390

14141391
/**

0 commit comments

Comments
 (0)