ServiceFactory::fromStr()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 18
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 24
ccs 14
cts 14
cp 1
crap 2
rs 9.6666
1
<?php
2
3
namespace Raigu\XRoad\SoapEnvelope;
4
5
use Raigu\XRoad\SoapEnvelope\Element\FragmentInjection;
6
use Raigu\XRoad\SoapEnvelope\Element\XmlInjectable;
7
8
/**
9
 * I create a service element of X-Road SOAP envelope
10
 * which can inject itself into proper place
11
 */
12
final class ServiceFactory
13
{
14
    /**
15
     * @param string $reference
16
     * @return XmlInjectable
17
     */
18 8
    public function fromStr(string $reference): XmlInjectable
19
    {
20 8
        $parts = explode('/', $reference);
21 8
        if (count($parts) !== 6) {
22 1
            throw new \Exception('Could not extract service parameters. Invalid format.');
23
        }
24
25
        $fragment = <<<EOD
26
<xrd:service id:objectType="SERVICE" 
27
    xmlns:xrd="http://x-road.eu/xsd/xroad.xsd"
28
    xmlns:id="http://x-road.eu/xsd/identifiers">
29 7
            <id:xRoadInstance>{$parts[0]}</id:xRoadInstance>
30 7
            <id:memberClass>{$parts[1]}</id:memberClass>
31 7
            <id:memberCode>{$parts[2]}</id:memberCode>
32 7
            <id:subsystemCode>{$parts[3]}</id:subsystemCode>
33 7
            <id:serviceCode>{$parts[4]}</id:serviceCode>
34 7
            <id:serviceVersion>{$parts[5]}</id:serviceVersion>
35
</xrd:service>
36
EOD;
37
38 7
        return new FragmentInjection(
39 7
            'http://schemas.xmlsoap.org/soap/envelope/',
40 7
            'Header',
41 7
            $fragment
42
        );
43
    }
44
}
45