HtmlMinifier::minify()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Imanghafoori\Widgets\Utils;
4
5
/**
6
 * Class Html Minifier.
7
 */
8
class HtmlMinifier
9
{
10
    private $replace = [
11
        '/<!--[\s\S]*?-->/' => '', //remove comments
12
        "/<\?php/" => '<?php ',
13
        "/\n([\S])/" => '$1',
14
        "/\r/" => '', // remove carriage return
15
        "/\n/" => '', // remove new lines
16
        "/\t/" => '', // remove tab
17
        "/\s+/" => ' ', // remove spaces
18
    ];
19
20
    /**
21
     * @param $htmlString string
22
     * @return string
23
     */
24 9
    public function minify(string $htmlString): string
25
    {
26 9
        return preg_replace(array_keys($this->replace), array_values($this->replace), $htmlString);
27
    }
28
}
29