complexNewAnalyzer = $complexNewAnalyzer; $this->nodeNameResolver = $nodeNameResolver; } /** * Matches * * $this->value = $param ?? 'default'; */ public function matchCoalesceAssignsToLocalPropertyNamed(Stmt $stmt, string $propertyName) : ?Coalesce { if (!$stmt instanceof Expression) { return null; } if (!$stmt->expr instanceof Assign) { return null; } $assign = $stmt->expr; if (!$assign->expr instanceof Coalesce) { return null; } $coalesce = $assign->expr; if (!$coalesce->right instanceof New_) { return null; } if ($this->complexNewAnalyzer->isDynamic($coalesce->right)) { return null; } if (!$this->isLocalPropertyFetchNamed($assign->var, $propertyName)) { return null; } return $assign->expr; } private function isLocalPropertyFetchNamed(Expr $expr, string $propertyName) : bool { if (!$expr instanceof PropertyFetch) { return \false; } if (!$this->nodeNameResolver->isName($expr->var, 'this')) { return \false; } return $this->nodeNameResolver->isName($expr->name, $propertyName); } }