Replacer::replace()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 9
rs 10
1
<?php
2
3
namespace gulch\Minify\Processor;
4
5
abstract class Replacer
6
{
7
    abstract public function getReplacePatternData(): array;
8
9
    public function process(string $buffer): string
10
    {
11
        if (\strlen($buffer) === 0) {
12
            return '';
13
        }
14
15
        return $this->replace(
16
            $this->getReplacePatternData(),
17
            $buffer
18
        );
19
    }
20
21
    public function replace(array $replace, string $buffer): string
22
    {
23
        $result = \preg_replace(
24
            \array_keys($replace),
25
            \array_values($replace),
26
            $buffer
27
        );
28
29
        return ($result === null) ? $buffer : $result;
30
    }
31
}
32