FragmentInjection   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
eloc 11
c 3
b 0
f 0
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A inject() 0 8 1
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