DOMElementInjection::inject()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Raigu\XRoad\SoapEnvelope\Element;
4
5
use DOMDocument;
6
use DOMElement;
7
8
/**
9
 * I am an XML element as DOMElement instance.
10
 *
11
 * I can append myself as a child to referred node.
12
 */
13
final class DOMElementInjection implements XmlInjectable
14
{
15
    /**
16
     * @var string
17
     */
18
    private $parentNS;
19
    /**
20
     * @var string
21
     */
22
    private $parentTagName;
23
    /**
24
     * @var DOMElement
25
     */
26
    private $child;
27
28
    public function inject(DOMDocument $dom): void
29
    {
30
        $elements = $dom->getElementsByTagNameNS($this->parentNS, $this->parentTagName);
31
        $elements->item(0)->appendChild($this->child);
32
    }
33
34
    public function __construct(string $parentNS, string $parentTagName, DOMElement $child)
35
    {
36
        $this->parentNS = $parentNS;
37
        $this->parentTagName = $parentTagName;
38
        $this->child = $child;
39
    }
40
}
41