Conditions | 3 |
Paths | 1 |
Total Lines | 26 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
19 | 4 | public function process(MinifyContext $context) |
|
20 | { |
||
21 | 4 | $booleanAttributes = implode('|', (new HtmlBooleanAttributeRepository())->getAttributes()); |
|
22 | |||
23 | 4 | return $context->setContents(preg_replace_callback( |
|
24 | '/ |
||
25 | \s # first match a whitespace which is an indication if its an attribute |
||
26 | 4 | ('.$booleanAttributes.') # match and capture a boolean attribute |
|
27 | \s* |
||
28 | = |
||
29 | \s* |
||
30 | ([\'"])? # optional to use a quote |
||
31 | (\1|true|false|([\s>"\'])) # match the boolean attribute name again or true|false |
||
32 | \2? # match the quote again |
||
33 | 4 | /xi', function ($match) { |
|
34 | 1 | if (isset($match[4])) { |
|
35 | 1 | return ' '.$match[1]; |
|
36 | } |
||
37 | |||
38 | 1 | if ($match[3] == 'false') { |
|
39 | 1 | return ''; |
|
40 | } |
||
41 | |||
42 | 1 | return ' '.$match[1]; |
|
43 | 4 | }, $context->getContents())); |
|
44 | } |
||
45 | |||
56 |