csscomb::parse_rules PHP Method

parse_rules() public method

Зависит от $this->mode Из $this->code['edited'] получает массив разбитый по }
public parse_rules ( )
    function parse_rules()
    {
        if ($this->mode === 'css-file') {
            // Отделяем всё после последней }
            // Например, @import и комментарии
            preg_match('@
                (
                    .*[^}]
                    }
                )
                (.*)
                @ismx', $this->code['edited'], $matches);
            $code_without_end = $matches[1];
            // Если что-то нашлось, выносим в отдельную строку
            $end_of_code = '';
            if ($matches[2]) {
                $end_of_code = $matches[2];
            }
            // Обрабатываем всё до последней }
            $code_without_end = $this->parse_root($code_without_end);
            // Склеиваем обратно
            $this->code['resorted'] = $code_without_end . $end_of_code;
        }
        // TODO: Написать тесты для этой части и переписать код
        if ($this->mode === 'style-attribute') {
            $this->code['resorted'] = $this->code['edited'];
            preg_match_all('@
                .*?[^"\']
                style=
                ["\']
                (.*?)
                ["\']
                @ismx', $this->code['edited'], $matches);
            $properties = $matches[1];
            //TODO: вынести вызов parse_prop в csscomb(), сделать чтобы parse_rules возвращала результат своей работы в виде $rules
            foreach ($properties as $props) {
                $r = $this->parse_properties($props);
                $this->code['resorted'] = str_replace($props, $r, $this->code['resorted']) . $end_of_code;
            }
        }
        if ($this->mode === 'properties') {
            $this->code['edited'] = "\n" . $this->code['edited'];
            $this->code['resorted'] = $this->parse_child($this->code['edited']);
            // Remove first line if it's empty
            if (strpos($this->code['resorted'], "\n") === 0) {
                $this->code['resorted'] = substr($this->code['resorted'], 1);
            }
            // Remove all new lines if css initially didn't have any
            if (substr_count($this->code['edited'], "\n") === 1) {
                $this->code['resorted'] = str_replace("\n", '', $this->code['resorted']);
            }
        }
    }