DeferredFragmentInjection   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 30
ccs 10
cts 10
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A inject() 0 8 1
1
<?php
2
3
namespace Raigu\XRoad\SoapEnvelope\Element;
4
5
use Closure;
6
use DOMDocument;
7
8
/**
9
 * I append XML fragment as child to referred node.
10
 * I defer fragment creation to the last moment before appending.
11
 */
12
final class DeferredFragmentInjection implements XmlInjectable
13
{
14
    /**
15
     * @var string
16
     */
17
    private $parentNS;
18
    /**
19
     * @var string
20
     */
21
    private $parentTagName;
22
    /**
23
     * @var Closure
24
     */
25
    private $fragment;
26
27 7
    public function inject(DOMDocument $dom): void
28
    {
29 7
        $elements = $dom->getElementsByTagNameNS($this->parentNS, $this->parentTagName);
30
31 7
        $fragment = $dom->createDocumentFragment();
32 7
        $fragment->appendXML(call_user_func($this->fragment));
33
34 7
        $elements->item(0)->appendChild($fragment);
35 7
    }
36
37 8
    public function __construct(string $parentNS, string $parentTagName, Closure $fragment)
38
    {
39 8
        $this->parentNS = $parentNS;
40 8
        $this->parentTagName = $parentTagName;
41 8
        $this->fragment = $fragment;
42 8
    }
43
}
44