ApplyAttributesProcessor   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 10
c 1
b 0
f 0
dl 0
loc 23
ccs 9
cts 10
cp 0.9
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 14 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 13
    public function __invoke(\DOMElement $svg, array $options = []): \DOMElement
26
    {
27 13
        foreach ($options as $key => $val) {
28 13
            if (in_array($key, $this->blocked)) {
29
                // Delete option attribute
30
                $svg->removeAttribute($key);
31 13
            } elseif ($val = is_string($val) ? $val : null) {
32
                // Set option attribute after clean
33 13
                $svg->removeAttribute($key);
34 13
                $svg->setAttribute($key, $val);
35
            }
36
        }
37
38 13
        return $svg;
39
    }
40
}
41