FragmentInjection::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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