Passed
Push — main ( 38d056...7e7092 )
by Oscar
12:07
created

ApplyAttributesProcessor::__invoke()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.6111
cc 5
nc 4
nop 2
crap 5
1
<?php
2
3
/*
4
 * This file is part of ocubom/twig-svg-extension
5
 *
6
 * © Oscar Cubo Medina <https://ocubom.github.io>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ocubom\Twig\Extension\Svg\Processor;
13
14
use function Ocubom\Twig\Extension\is_string;
15
16
class ApplyAttributesProcessor implements ProcessorInterface
17
{
18
    private array $blocked;
19
20 3
    public function __construct(string ...$blocked)
21
    {
22 3
        $this->blocked = $blocked;
23
    }
24
25 12
    public function __invoke(\DOMElement $svg, array $options = []): \DOMElement
26
    {
27 12
        foreach ($options as $key => $val) {
28 12
            if (in_array($key, $this->blocked)) {
29
                // Delete option attribute
30 12
                $svg->removeAttribute($key);
31 12
            } elseif ($val = is_string($val) ? $val : null) {
32
                // Set option attribute after clean
33 12
                $svg->removeAttribute($key);
34 12
                $svg->setAttribute($key, $val);
35
            }
36
        }
37
38 12
        return $svg;
39
    }
40
}
41