nodeNameResolver = $nodeNameResolver;
$this->betterNodeFinder = $betterNodeFinder;
$this->propertyFetchAnalyzer = $propertyFetchAnalyzer;
}
/**
* Matches:
* list([1, 2]) = each($items)
*/
public function matchListAndEach(Assign $assign) : ?ListAndEach
{
// could be behind error suppress
if ($assign->expr instanceof ErrorSuppress) {
$errorSuppress = $assign->expr;
$bareExpr = $errorSuppress->expr;
} else {
$bareExpr = $assign->expr;
}
if (!$bareExpr instanceof FuncCall) {
return null;
}
if (!$assign->var instanceof List_) {
return null;
}
if (!$this->nodeNameResolver->isName($bareExpr, 'each')) {
return null;
}
// no placeholders
if ($bareExpr->isFirstClassCallable()) {
return null;
}
return new ListAndEach($assign->var, $bareExpr);
}
public function isLeftPartOfAssign(Node $node) : bool
{
if ($node->getAttribute(AttributeKey::IS_BEING_ASSIGNED) === \true) {
return \true;
}
if ($node->getAttribute(AttributeKey::IS_ASSIGN_REF_EXPR) === \true) {
return \true;
}
return $node->getAttribute(AttributeKey::IS_ASSIGN_OP_VAR) === \true;
}
/**
* @api doctrine
* @return array