PHPStan\Analyser\NodeScopeResolver::lookForAssignsInBranches PHP Method

lookForAssignsInBranches() private method

private lookForAssignsInBranches ( Scope $initialScope, array $statementsLists, boolean $isSwitchCase = false ) : Scope
$initialScope Scope
$statementsLists array
$isSwitchCase boolean
return Scope
    private function lookForAssignsInBranches(Scope $initialScope, array $statementsLists, bool $isSwitchCase = false) : Scope
    {
        $intersectedScope = null;
        $previousBranchScope = null;
        foreach ($statementsLists as $i => $statementList) {
            $statements = $statementList->getStatements();
            $branchScope = $statementList->getScope();
            if ($statements === null) {
                continue;
            }
            $mergeWithPrevious = $isSwitchCase;
            foreach ($statements as $statement) {
                $branchScope = $this->lookForAssigns($branchScope, $statement);
                $hasStatementEarlyTermination = $this->hasStatementEarlyTermination($statement, $branchScope);
                if ($hasStatementEarlyTermination && !$isSwitchCase) {
                    continue 2;
                }
            }
            if ($intersectedScope === null) {
                $intersectedScope = $initialScope->addVariables($branchScope);
            } elseif ($mergeWithPrevious) {
                if ($previousBranchScope !== null) {
                    $intersectedScope = $branchScope->addVariables($previousBranchScope);
                }
            } else {
                $intersectedScope = $branchScope->intersectVariables($intersectedScope);
            }
            $previousBranchScope = $branchScope;
        }
        return $intersectedScope !== null ? $intersectedScope : $initialScope;
    }