Passed
Push — master ( 59db0f...9fb939 )
by Brent
04:37
created

SassParser::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Brendt\Stitcher\Parser;
4
5
use Brendt\Stitcher\Config;
6
use Leafo\ScssPhp\Compiler;
7
use Symfony\Component\Finder\Finder;
8
use Symfony\Component\Finder\SplFileInfo;
9
10
/**
11
 * The SassParser take a path to one or more sass files, compiles it to CSS and returns that CSS.
12
 */
13
class SassParser implements Parser
14
{
15
16
    /**
17
     * @var Compiler
18
     */
19
    private $sass;
20
21
    /**
22
     * @var string
23
     */
24
    private $srcDir;
25
26
    /**
27
     * SassParser constructor.
28
     *
29
     * @param Compiler $sass
30
     * @param string   $srcDir
31
     */
32
    public function __construct(Compiler $sass, string $srcDir) {
33
        $this->sass = $sass;
34
        $this->srcDir = $srcDir;
35
    }
36
37
    /**
38
     * @param $path
39
     *
40
     * @return string
41
     */
42
    public function parse($path) {
43
        /** @var SplFileInfo[] $files */
44
        $files = Finder::create()->files()->in($this->srcDir)->path(trim($path, '/'));
45
        $data = '';
46
47
        foreach ($files as $file) {
48
            $data .= $this->sass->compile($file->getContents());
49
        }
50
51
        return $data;
52
    }
53
54
}
55