Passed
Push — main ( 77e259...371264 )
by Oscar
08:09 queued 06:34
created

SvgTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 11
c 1
b 0
f 0
dl 0
loc 29
ccs 8
cts 8
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 15 2
A __toString() 0 3 1
A getElement() 0 3 1
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;
13
14
use Ocubom\Twig\Extension\Svg\Exception\RuntimeException;
15
16
trait SvgTrait
17
{
18
    protected \DOMElement $svg;
19
20 3
    public function getElement(): \DOMElement
21
    {
22 3
        return $this->svg;
23
    }
24
25 2
    public function render(): string
26
    {
27
        assert($this->svg->ownerDocument instanceof \DOMDocument);
28
29 2
        $output = $this->svg->ownerDocument->saveXML($this->svg);
30 2
        if (false === $output) {
31
            // @codeCoverageIgnoreStart
32
            throw new RuntimeException(sprintf(
33
                'Unable to render %s to XML',
34
                get_class($this->svg)
35
            ));
36
            // @codeCoverageIgnoreEnd
37
        }
38
39 2
        return $output;
40
    }
41
42 2
    public function __toString()
43
    {
44 2
        return $this->render();
45
    }
46
}
47