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

Crunched::blockSelectors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
rs 10
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
 * Crunched formatter
20
 *
21
 * @author Anthon Pang <[email protected]>
22
 */
23
class Crunched 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) === '/*') {
51
                unset($block->lines[$index]);
52
            }
53
        }
54
55
        $this->write($inner . implode($glue, $block->lines));
56
57
        if (! empty($block->children)) {
58
            $this->write($this->break);
59
        }
60
    }
61
62
    /**
63
     * Output block selectors
64
     *
65
     * @param \ScssPhp\ScssPhp\Formatter\OutputBlock $block
66
     */
67
    protected function blockSelectors(OutputBlock $block)
68
    {
69
        $inner = $this->indentStr();
70
71
        $this->write(
72
            $inner
73
            . implode(
74
                $this->tagSeparator,
75
                str_replace([' > ', ' + ', ' ~ '], ['>', '+', '~'], $block->selectors)
76
            )
77
            . $this->open . $this->break
78
        );
79
    }
80
}
81