function VariableAnalysisSniff::processVariableAsListShorthandAssignment
* Processes variables destructured from an array using shorthand list assignment. * * This will record the definition and assignment of variables defined using * the format: * * ``` * [ $foo, $bar, $baz ] = $ary; * ``` * * Can be called for any token and will return false if the variable is not * of this type. * *
Parameters
File $phpcsFile: * @param int $stackPtr * @param string $varName * @param int $currScope * * @return bool
1 call to VariableAnalysisSniff::processVariableAsListShorthandAssignment()
- VariableAnalysisSniff::processVariable in vendor/
sirbrillig/ phpcs-variable-analysis/ VariableAnalysis/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php - * Process a normal variable in the code. * * Most importantly, this function determines if the variable use is a "read" * (using the variable for something) or a "write" (an assignment) or, * sometimes, both at once. * …
File
-
vendor/
sirbrillig/ phpcs-variable-analysis/ VariableAnalysis/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php, line 1196
Class
Namespace
VariableAnalysis\Sniffs\CodeAnalysisCode
protected function processVariableAsListShorthandAssignment(File $phpcsFile, $stackPtr, $varName, $currScope) {
// OK, are we within a [ ... ] construct?
$openPtr = Helpers::findContainingOpeningSquareBracket($phpcsFile, $stackPtr);
if (!is_int($openPtr)) {
return false;
}
// OK, we're a [ ... ] construct... are we being assigned to?
$assignments = Helpers::getListAssignments($phpcsFile, $openPtr);
if (!$assignments) {
return false;
}
$matchingAssignment = array_reduce($assignments, function ($thisAssignment, $assignment) use ($stackPtr) {
if ($assignment === $stackPtr) {
return $assignment;
}
return $thisAssignment;
});
if (!$matchingAssignment) {
return false;
}
// Yes, we're being assigned.
$this->markVariableAssignment($varName, $stackPtr, $currScope);
return true;
}