Completed
Push — master ( 2c7ea9...284ef7 )
by Iman
01:59
created

HtmlMinifier::minify()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Imanghafoori\Widgets\Utils;
4
5
6
class HtmlMinifier
7
{
8
    private $replace = [
9
        '<!--(.*?)-->' => '', //remove comments
10
        "/<\?php/" => '<?php ',
11
        "/\n([\S])/" => '$1',
12
        "/\r/" => '', // remove carrage return
13
        "/\n/" => '', // remove new lines
14
        "/\t/" => '', // remove tab
15
        "/\s+/" => ' ', // remove spaces
16
    ];
17
    /**
18
     * @return null
19
     */
20
    function minify($htmlString)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
21
    {
22
        return preg_replace(array_keys($this->replace), array_values($this->replace), $htmlString);
23
    }
24
}