Passed
Push — master ( 78e8a4...90a5d4 )
by Enjoys
02:13
created

CssMinify::setContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Enjoys\AssetsCollector\Content\Minify\Adapters;
6
7
use Enjoys\AssetsCollector\Content\Minify\MinifyInterface;
8
use Enjoys\Traits\Options;
9
use tubalmartin\CssMin\Minifier as CSSmin;
10
11
/**
12
 * Class CssMinify
13
 * @package Enjoys\AssetsCollector\Content\Minify\Adapters
14
 */
15
class CssMinify implements MinifyInterface
16
{
17
    use Options;
18
19
    private string $content = '';
20
21
    /**
22
     * CssMinify constructor.
23
     * @param array $minifyOptions
24
     */
25 9
    public function __construct(array $minifyOptions = [])
26
    {
27 9
        $this->setOptions($minifyOptions);
28 9
    }
29
30 4
    public function setContent(string $content): void
31
    {
32 4
        $this->content = $content;
33 4
    }
34
35
    /**
36
     * @return string
37
     */
38 3
    public function getContent(): string
39
    {
40 3
        $compressor = new CSSMin();
41 3
        $compressor->keepSourceMapComment((bool)$this->getOption('keepSourceMapComment', false));
42
        // Remove important comments from output.
43 3
        $compressor->removeImportantComments((bool)$this->getOption('removeImportantComments', true));
44
        // Split long lines in the output approximately every 1000 chars.
45 3
        $compressor->setLineBreakPosition((int)$this->getOption('setLineBreakPosition', 1000));
46 3
        $compressor->setMaxExecutionTime((int)$this->getOption('setMaxExecutionTime', 60));
47
        // Override any PHP configuration options before calling run() (optional)
48 3
        $compressor->setMemoryLimit((string)$this->getOption('setMemoryLimit', '256M'));
49 3
        $compressor->setPcreBacktrackLimit((int)$this->getOption('setPcreBacktrackLimit', 1000000));
50 3
        $compressor->setPcreRecursionLimit((int)$this->getOption('setPcreRecursionLimit', 500000));
51
        // Compress the CSS code!
52 3
        return $compressor->run($this->content);
53
    }
54
}
55