Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion Sniffs/CodeAnalysis/VariableAnalysisSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,34 @@ protected function checkForFunctionPrototype(
}
return false;
}

/**
* isset() marks a variable as declared
*/
protected function checkForIsset(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr,
$varName,
$currScope
) {
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];

// Are we an isset() parameter?
if (($openPtr = $this->findContainingBrackets($phpcsFile, $stackPtr)) === false) {
return false;
}

$catchPtr = $phpcsFile->findPrevious(T_WHITESPACE,
$openPtr - 1, null, true, null, true);
if (($catchPtr !== false) &&
($tokens[$catchPtr]['code'] === T_ISSET)) {
$this->markVariableAssignment($varName, $stackPtr, $currScope);
return true;
}
return false;
}

protected function checkForCatchBlock(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr,
Expand Down Expand Up @@ -1262,6 +1289,11 @@ protected function processVariable(
return;
}

// Are we an isset() parameter?
if ($this->checkForIsset($phpcsFile, $stackPtr, $varName, $currScope)) {
return;
}

// Are we a catch parameter?
if ($this->checkForCatchBlock($phpcsFile, $stackPtr, $varName, $currScope)) {
return;
Expand Down Expand Up @@ -1495,4 +1527,4 @@ protected function processScopeClose(
}
}//end class

?>
?>