Leafo\ScssPhp\Compiler::sortArgs PHP Method

sortArgs() protected method

Sorts keyword arguments
protected sortArgs ( array $prototype, array $args ) : array
$prototype array
$args array
return array
    protected function sortArgs($prototype, $args)
    {
        $keyArgs = [];
        $posArgs = [];
        // separate positional and keyword arguments
        foreach ($args as $arg) {
            list($key, $value) = $arg;
            $key = $key[1];
            if (empty($key)) {
                $posArgs[] = $value;
            } else {
                $keyArgs[$key] = $value;
            }
        }
        if (!isset($prototype)) {
            return [$posArgs, $keyArgs];
        }
        // copy positional args
        $finalArgs = array_pad($posArgs, count($prototype), null);
        // overwrite positional args with keyword args
        foreach ($prototype as $i => $names) {
            foreach ((array) $names as $name) {
                if (isset($keyArgs[$name])) {
                    $finalArgs[$i] = $keyArgs[$name];
                }
            }
        }
        return [$finalArgs, $keyArgs];
    }
Compiler