Passed
Branch reduce-soap-envelope-builder-c... (c98539)
by Rait
02:14
created

RepresentedParty::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
nc 2
nop 1
dl 0
loc 19
ccs 11
cts 11
cp 1
crap 2
rs 9.9
c 1
b 0
f 0
1
<?php
2
3
namespace Raigu\XRoad\SoapEnvelope;
4
5
use Raigu\XRoad\SoapEnvelope\Element\DOMElementInjection;
6
use Raigu\XRoad\SoapEnvelope\Element\FragmentInjection;
7
use Traversable;
8
9
/**
10
 * I am the party who is represented by client.
11
 *
12
 * I know how to inject myself into SOAP envelope header.
13
 *
14
 * I fallow the specification "Third Party Representation Extension"
15
 * @see https://x-tee.ee/docs/live/xroad/pr-third_party_representation_extension.html
16
 */
17
final class RepresentedParty extends AggregatedElement
18
{
19
    /**
20
     * RepresentedParty constructor.
21
     * @param Traversable $reference iterator over data describing represented
22
     *        party. Iterator must return key value pairs where key represents
23
     *        the tag name and value tag value in SOAP header.
24
     */
25 1
    public function __construct(Traversable $reference)
26
    {
27
        $elements = [
28 1
            new FragmentInjection(
29 1
                'http://schemas.xmlsoap.org/soap/envelope/',
30 1
                'Header',
31 1
                '<repr:representedParty xmlns:repr="http://x-road.eu/xsd/representation.xsd"/>'
32
            ),
33
        ];
34
35 1
        foreach ($reference as $name => $value) {
36 1
            $elements[] = new DOMElementInjection(
37 1
                'http://x-road.eu/xsd/representation.xsd',
38 1
                'representedParty',
39 1
                new \DOMElement($name, $value, 'http://x-road.eu/xsd/representation.xsd')
40
            );
41
        }
42
43 1
        parent::__construct(...$elements);
44 1
    }
45
}
46