Leafo\ScssPhp\Compiler::extractRelationshipFromFragment PHP Method

extractRelationshipFromFragment() protected method

When extracting the last portion of a selector we will be left with a fragment which may end with a direction relationship combinator. This method will extract the relationship fragment and return it along side the rest.
protected extractRelationshipFromFragment ( array $fragment ) : array
$fragment array The selector fragment maybe ending with a direction relationship combinator.
return array The selector without the relationship fragment if any, the relationship fragment.
    protected function extractRelationshipFromFragment(array $fragment)
    {
        $parents = [];
        $children = [];
        $j = $i = count($fragment);
        for (;;) {
            $children = $j != $i ? array_slice($fragment, $j, $i - $j) : [];
            $parents = array_slice($fragment, 0, $j);
            $slice = end($parents);
            if (empty($slice) || !$this->isImmediateRelationshipCombinator($slice[0])) {
                break;
            }
            $j -= 2;
        }
        return [$parents, $children];
    }
Compiler