JavascriptEventsMinifier   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 35
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A provides() 0 4 1
A process() 0 15 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