RepresentedPartyFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromStr() 0 18 2
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 represented party element
10
 * which can inject itself into X-Road SOAP Envelope.
11
 *
12
 * I create element according to the technical specification:
13
 * https://x-tee.ee/docs/live/xroad/pr-third_party_representation_extension.html
14
 */
15
final class RepresentedPartyFactory
16
{
17
    /**
18
     * @param string $representedParty
19
     * @return XmlInjectable
20
     */
21 1
    public function fromStr(string $representedParty): XmlInjectable
22
    {
23 1
        $fragment = ['<repr:representedParty xmlns:repr="http://x-road.eu/xsd/representation.xsd">'];
24
25 1
        $parts = explode('/', $representedParty, 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
        return new FragmentInjection(
36 1
            'http://schemas.xmlsoap.org/soap/envelope/',
37 1
            'Header',
38 1
            implode('', $fragment)
39
        );
40
    }
41
}
42