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

StrAsClient::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 19
ccs 10
cts 10
cp 1
crap 1
rs 9.7998
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
/**
10
 * I create a service element of X-Road SOAP envelope
11
 * which can inject itself into proper place in DOMDocument
12
 */
13
final class StrAsClient implements XmlInjectable
14
{
15
    /**
16
     * @var FragmentInjection
17
     */
18
    private $injection;
19
20 1
    public function inject(DOMDocument $dom): void
21
    {
22 1
        $this->injection->inject($dom);
23 1
    }
24
25 1
    public function __construct(string $reference)
26
    {
27 1
        $client = new StrAsClientReference($reference);
28
29
        $fragment = <<<EOD
30 1
<xrd:client id:objectType="SUBSYSTEM" 
31
    xmlns:xrd="http://x-road.eu/xsd/xroad.xsd"
32
    xmlns:id="http://x-road.eu/xsd/identifiers">
33 1
            <id:xRoadInstance>{$client->xRoadInstance()}</id:xRoadInstance>
34 1
            <id:memberClass>{$client->memberClass()}</id:memberClass>
35 1
            <id:memberCode>{$client->memberCode()}</id:memberCode>
36 1
            <id:subsystemCode>{$client->subSystemCode()}</id:subsystemCode>
37
</xrd:client>
38
EOD;
39
40 1
        $this->injection = new FragmentInjection(
41 1
            'http://schemas.xmlsoap.org/soap/envelope/',
42 1
            'Header',
43
            $fragment
44
        );
45 1
    }
46
}
47