Passed
Branch reduce-soap-envelope-builder-c... (f028c1)
by Rait
07:42
created

StrAsRepresentedParty::inject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Raigu\XRoad\SoapEnvelope;
4
5
use DOMDocument;
6
use Raigu\XRoad\SoapEnvelope\Element\FragmentInjection;
7
use Raigu\XRoad\SoapEnvelope\Element\XmlInjectable;
8
9
final class StrAsRepresentedParty implements XmlInjectable
10
{
11
    /**
12
     * @var XmlInjectable
13
     */
14
    private $injection;
15
16 1
    public function inject(DOMDocument $dom): void
17
    {
18 1
        $this->injection->inject($dom);
19 1
    }
20
21 1
    public function __construct(string $reference)
22
    {
23 1
        $fragment = ['<repr:representedParty xmlns:repr="http://x-road.eu/xsd/representation.xsd">'];
24
25 1
        $parts = explode('/', $reference, 2);
26
27 1
        if (count($parts) > 1) {
28 1
            $fragment[] = '<repr:partyClass>' . $parts[0] . '</repr:partyClass>';
29 1
            array_shift($parts);
30
        }
31
32 1
        $fragment[] = '<repr:partyCode>' . $parts[0] . '</repr:partyCode>';
33 1
        $fragment[] = '</repr:representedParty>';
34
35 1
        $this->injection = new FragmentInjection(
36 1
            'http://schemas.xmlsoap.org/soap/envelope/',
37 1
            'Header',
38 1
            implode('', $fragment)
39
        );
40
41 1
    }
42
}
43