Minifier   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 13
c 3
b 0
f 0
dl 0
loc 33
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addProcessor() 0 5 1
A createDefault() 0 7 1
A __construct() 0 3 1
A process() 0 7 2
1
<?php
2
3
namespace gulch\Minify;
4
5
use gulch\Minify\Contract\ProcessorInterface;
6
use gulch\Minify\Processor\HtmlCommentsRemover;
7
use gulch\Minify\Processor\InlineCssMinifier;
8
use gulch\Minify\Processor\InlineJavascriptMinifier;
9
use gulch\Minify\Processor\WhitespacesRemover;
10
11
class Minifier implements ProcessorInterface
12
{
13
    /** @var array */
14
    private $processors;
15
16
    public function __construct(ProcessorInterface ...$processors)
17
    {
18
        $this->processors = $processors;
19
    }
20
21
    public function process(string $buffer): string
22
    {
23
        foreach ($this->processors as $processor) {
24
            $buffer = $processor->process($buffer);
25
        }
26
27
        return $buffer;
28
    }
29
30
    public function addProcessor(ProcessorInterface $processor): self
31
    {
32
        $this->processors[] = $processor;
33
34
        return $this;
35
    }
36
37
    public static function createDefault(): self
38
    {
39
        return new self(
40
            new WhitespacesRemover,
41
            new InlineCssMinifier,
42
            new InlineJavascriptMinifier,
43
            new HtmlCommentsRemover
44
        );
45
    }
46
}
47