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

Expanded   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A indentStr() 0 3 1
A blockLines() 0 16 5
A __construct() 0 10 1
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
 * Expanded formatter
20
 *
21
 * @author Leaf Corcoran <[email protected]>
22
 */
23
class Expanded extends Formatter
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function __construct()
29
    {
30
        $this->indentLevel = 0;
31
        $this->indentChar = '  ';
32
        $this->break = "\n";
33
        $this->open = ' {';
34
        $this->close = '}';
35
        $this->tagSeparator = ', ';
36
        $this->assignSeparator = ': ';
37
        $this->keepSemicolons = true;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    protected function indentStr()
44
    {
45
        return str_repeat($this->indentChar, $this->indentLevel);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    protected function blockLines(OutputBlock $block)
52
    {
53
        $inner = $this->indentStr();
54
55
        $glue = $this->break . $inner;
56
57
        foreach ($block->lines as $index => $line) {
58
            if (substr($line, 0, 2) === '/*') {
59
                $block->lines[$index] = preg_replace('/\r\n?|\n|\f/', $this->break, $line);
60
            }
61
        }
62
63
        $this->write($inner . implode($glue, $block->lines));
64
65
        if (empty($block->selectors) || ! empty($block->children)) {
66
            $this->write($this->break);
67
        }
68
    }
69
}
70