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

SvgTrait::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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