Leafo\ScssPhp\Compiler::flattenSelectors PHP Method

flattenSelectors() protected method

Flatten selectors
protected flattenSelectors ( Leafo\ScssPhp\Formatter\OutputBlock $block, string $parentKey = null )
$block Leafo\ScssPhp\Formatter\OutputBlock
$parentKey string
    protected function flattenSelectors(OutputBlock $block, $parentKey = null)
    {
        if ($block->selectors) {
            $selectors = [];
            foreach ($block->selectors as $s) {
                $selectors[] = $s;
                if (!is_array($s)) {
                    continue;
                }
                // check extends
                if (!empty($this->extendsMap)) {
                    $this->matchExtends($s, $selectors);
                    // remove duplicates
                    array_walk($selectors, function (&$value) {
                        $value = serialize($value);
                    });
                    $selectors = array_unique($selectors);
                    array_walk($selectors, function (&$value) {
                        $value = unserialize($value);
                    });
                }
            }
            $block->selectors = [];
            $placeholderSelector = false;
            foreach ($selectors as $selector) {
                if ($this->hasSelectorPlaceholder($selector)) {
                    $placeholderSelector = true;
                    continue;
                }
                $block->selectors[] = $this->compileSelector($selector);
            }
            if ($placeholderSelector && 0 === count($block->selectors) && null !== $parentKey) {
                unset($block->parent->children[$parentKey]);
                return;
            }
        }
        foreach ($block->children as $key => $child) {
            $this->flattenSelectors($child, $key);
        }
    }
Compiler