Passed
Push — trunk ( f797a9...e92141 )
by Christian
22:24 queued 10:00
created

ScssPhpCompiler::filesHandledInternal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Storefront\Theme;
4
5
use ScssPhp\ScssPhp\Compiler;
6
use ScssPhp\ScssPhp\OutputStyle;
7
8
/**
9
 * @package storefront
10
 *
11
 * @internal - may be changed in the future
12
 */
13
class ScssPhpCompiler extends AbstractScssCompiler
14
{
15
    private Compiler $compiler;
16
17
    /**
18
     * @var array<string, mixed>|null
19
     */
20
    private ?array $cacheOptions;
21
22
    /**
23
     * @param array<string, mixed>|null $cacheOptions
24
     */
25
    public function __construct(?array $cacheOptions = null)
26
    {
27
        $this->compiler = new Compiler($cacheOptions);
28
        $this->cacheOptions = $cacheOptions;
29
    }
30
31
    public function reset(): void
32
    {
33
        $this->compiler = new Compiler($this->cacheOptions);
34
    }
35
36
    public function compileString(AbstractCompilerConfiguration $config, string $scss, ?string $path = null): string
37
    {
38
        $outputStyle = $config->getValue('outputStyle');
39
40
        if ($outputStyle === OutputStyle::COMPRESSED || $outputStyle === OutputStyle::EXPANDED) {
41
            $this->compiler->setOutputStyle($outputStyle);
42
        }
43
44
        $importPaths = $config->getValue('importPaths');
45
46
        if ($importPaths !== null) {
47
            $this->compiler->setImportPaths($importPaths);
48
        }
49
50
        $css = $this->compiler->compileString($scss, $path)->getCss();
51
52
        $this->reset(); // Reset compiler for multiple usage
53
54
        return $css;
55
    }
56
}
57