Passed
Push — master ( b558c2...d01ccb )
by Chris
04:06
created

Compressed   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A blockSelectors() 0 11 1
A blockLines() 0 18 6
A __construct() 0 10 1
1
<?php
2
/**
3
 * SCSSPHP
4
 *
5
 * @copyright 2012-2018 Leaf Corcoran
6
 *
7
 * @license http://opensource.org/licenses/MIT MIT
8
 *
9
 * @link http://leafo.github.io/scssphp
10
 */
11
12
namespace Leafo\ScssPhp\Formatter;
13
14
use Leafo\ScssPhp\Formatter;
15
use Leafo\ScssPhp\Formatter\OutputBlock;
16
17
/**
18
 * Compressed formatter
19
 *
20
 * @author Leaf Corcoran <[email protected]>
21
 */
22
class Compressed extends Formatter
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function __construct()
28
    {
29
        $this->indentLevel = 0;
30
        $this->indentChar = '  ';
31
        $this->break = '';
32
        $this->open = '{';
33
        $this->close = '}';
34
        $this->tagSeparator = ',';
35
        $this->assignSeparator = ':';
36
        $this->keepSemicolons = false;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function blockLines(OutputBlock $block)
43
    {
44
        $inner = $this->indentStr();
45
46
        $glue = $this->break . $inner;
47
48
        foreach ($block->lines as $index => $line) {
49
            if (substr($line, 0, 2) === '/*' && substr($line, 2, 1) !== '!') {
50
                unset($block->lines[$index]);
51
            } elseif (substr($line, 0, 3) === '/*!') {
52
                $block->lines[$index] = '/*' . substr($line, 3);
53
            }
54
        }
55
56
        $this->write($inner . implode($glue, $block->lines));
57
58
        if (! empty($block->children)) {
59
            $this->write($this->break);
60
        }
61
    }
62
}
63