JavascriptEventsMinifier::provides()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
ccs 2
cts 2
cp 1
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace ArjanSchouten\HtmlMinifier\Minifiers\Html;
4
5
use ArjanSchouten\HtmlMinifier\Constants;
6
use ArjanSchouten\HtmlMinifier\Minifiers\MinifierInterface;
7
use ArjanSchouten\HtmlMinifier\MinifyContext;
8
use ArjanSchouten\HtmlMinifier\Options;
9
10
class JavascriptEventsMinifier implements MinifierInterface
11
{
12
    /**
13
     * Minify javascript prefixes on html event attributes.
14
     *
15
     * @param \ArjanSchouten\HtmlMinifier\MinifyContext $context
16
     *
17
     * @return \ArjanSchouten\HtmlMinifier\MinifyContext
18
     */
19 2
    public function process(MinifyContext $context)
20
    {
21 2
        $contents = preg_replace_callback(
22
            '/'.
23 2
                Constants::$htmlEventNamePrefix.Constants::ATTRIBUTE_NAME_REGEX.'   # Match an on{attribute}
24
                \s*=\s*             # Match equals sign with optional whitespaces around it
25
                ["\']?              # Match an optional quote
26
                \s*javascript:      # Match the text "javascript:" which should be removed
27
            /xis',
28 2
            function ($match) {
29 1
                return str_replace('javascript:', '', $match[0]);
30 2
            }, $context->getContents());
31
32 2
        return $context->setContents($contents);
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::REMOVE_DEFAULTS;
43
    }
44
}
45