CommentMinifier::process()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 1
nop 1
crap 2
1
<?php
2
3
namespace ArjanSchouten\HtmlMinifier\Minifiers\Html;
4
5
use ArjanSchouten\HtmlMinifier\Minifiers\MinifierInterface;
6
use ArjanSchouten\HtmlMinifier\MinifyContext;
7
use ArjanSchouten\HtmlMinifier\Options;
8
use Illuminate\Support\Str;
9
10
class CommentMinifier implements MinifierInterface
11
{
12
    /**
13
     * Replace remaining comments.
14
     *
15
     * @param \ArjanSchouten\HtmlMinifier\MinifyContext $context
16
     *
17
     * @return \ArjanSchouten\HtmlMinifier\MinifyContext
18
     */
19 5
    public function process(MinifyContext $context)
20
    {
21 5
        return $context->setContents(preg_replace_callback(
22 5
            '/
23
                <!          # search for the start of a comment
24
                    [^>]*   # search for everything without a ">"
25
                >           # match the end of the comment
26 5
            /xs', function ($match) {
27 2
            if (Str::contains(strtolower($match[0]), 'doctype')) {
28 1
                return $match[0];
29
            }
30
31 2
            return '';
32 5
        }, $context->getContents()));
33
    }
34
35
    /**
36
     * Indicates if minification rules depends on command options.
37
     *
38
     * @return string
39
     */
40 3
    public function provides()
41
    {
42 3
        return Options::COMMENTS;
43
    }
44
}
45