Passed
Push — master ( d4a329...711fef )
by Jeroen De
03:36
created

Compressed::blockLines()   A

Complexity

Conditions 6
Paths 8

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 10
c 1
b 0
f 0
nc 8
nop 1
dl 0
loc 18
rs 9.2222
1
<?php
2
3
/**
4
 * SCSSPHP
5
 *
6
 * @copyright 2012-2020 Leaf Corcoran
7
 *
8
 * @license http://opensource.org/licenses/MIT MIT
9
 *
10
 * @link http://scssphp.github.io/scssphp
11
 */
12
13
namespace ScssPhp\ScssPhp\Formatter;
14
15
use ScssPhp\ScssPhp\Formatter;
16
use ScssPhp\ScssPhp\Formatter\OutputBlock;
17
18
/**
19
 * Compressed formatter
20
 *
21
 * @author Leaf Corcoran <[email protected]>
22
 */
23
class Compressed extends Formatter
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function __construct()
29
    {
30
        $this->indentLevel = 0;
31
        $this->indentChar = '  ';
32
        $this->break = '';
33
        $this->open = '{';
34
        $this->close = '}';
35
        $this->tagSeparator = ',';
36
        $this->assignSeparator = ':';
37
        $this->keepSemicolons = false;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function blockLines(OutputBlock $block)
44
    {
45
        $inner = $this->indentStr();
46
47
        $glue = $this->break . $inner;
48
49
        foreach ($block->lines as $index => $line) {
50
            if (substr($line, 0, 2) === '/*' && substr($line, 2, 1) !== '!') {
51
                unset($block->lines[$index]);
52
            } elseif (substr($line, 0, 3) === '/*!') {
53
                $block->lines[$index] = '/*' . substr($line, 3);
54
            }
55
        }
56
57
        $this->write($inner . implode($glue, $block->lines));
58
59
        if (! empty($block->children)) {
60
            $this->write($this->break);
61
        }
62
    }
63
64
    /**
65
     * Output block selectors
66
     *
67
     * @param \ScssPhp\ScssPhp\Formatter\OutputBlock $block
68
     */
69
    protected function blockSelectors(OutputBlock $block)
70
    {
71
        $inner = $this->indentStr();
72
73
        $this->write(
74
            $inner
75
            . implode(
76
                $this->tagSeparator,
77
                str_replace([' > ', ' + ', ' ~ '], ['>', '+', '~'], $block->selectors)
78
            )
79
            . $this->open . $this->break
80
        );
81
    }
82
}
83