Base::element()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
namespace nstdio\svg;
3
4
use nstdio\svg\xml\DOMWrapper;
5
6
/**
7
 * Class Base
8
 *
9
 * @package nstdio\svg
10
 * @author  Edgar Asatryan <[email protected]>
11
 */
12
abstract class Base
13
{
14
    /**
15
     *
16
     */
17
    const DOM_VERSION = '1.0';
18
19
    /**
20
     *
21
     */
22
    const DOM_ENCODING = 'utf-8';
23
24
    /**
25
     *
26
     */
27
    const XML_NS = 'http://www.w3.org/2000/svg';
28
29
    /**
30
     *
31
     */
32
    const XML_NS_XLINK = 'http://www.w3.org/1999/xlink';
33
34
    /**
35
     * @var XMLDocumentInterface
36
     */
37
    protected $domImpl;
38
39
40
    /**
41
     * Base constructor.
42
     *
43
     * @param XMLDocumentInterface|null $dom
44
     */
45 150
    public function __construct(XMLDocumentInterface $dom = null)
46
    {
47 150
        if (!extension_loaded('libxml')) {
48
            throw new \RuntimeException('The libxml extension is disabled. It is necessary to work with XML. You can try to recompile PHP with --with-libxml-dir=<location>.');
49
        }
50 150
        if ($dom !== null) {
51
            $this->domImpl = $dom;
52
        } else {
53 150
            if (DOMWrapper::isLoaded()) {
54 150
                $this->domImpl = new DOMWrapper();
55 150
            }
56
        }
57 150
    }
58
59
    /**
60
     * @param             $name
61
     * @param string|null $text
62
     *
63
     * @return XMLDocumentInterface
64
     */
65 150
    protected function element($name, $text = null)
66
    {
67 150
        return $this->domImpl->createElement($name, $text);
68
    }
69
}