HtmlMinifier   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 19
ccs 2
cts 2
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A minify() 0 3 1
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