RepresentedParty   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 2
1
<?php
2
3
namespace Raigu\XRoad\SoapEnvelope;
4
5
use Raigu\XRoad\SoapEnvelope\Element\AbstractElement;
6
use Raigu\XRoad\SoapEnvelope\Element\DOMElementInjection;
7
use Raigu\XRoad\SoapEnvelope\Element\FragmentInjection;
8
use Traversable;
9
10
/**
11
 * I am the party who is represented by client.
12
 *
13
 * I can inject myself into SOAP envelope header.
14
 *
15
 * I fallow the specification "Third Party Representation Extension"
16
 * @see https://x-tee.ee/docs/live/xroad/pr-third_party_representation_extension.html
17
 */
18
final class RepresentedParty extends AbstractElement
19
{
20
    /**
21
     * RepresentedParty constructor.
22
     * @param Traversable|array $reference associative array of data describing
23
     *        the party being represented by client. Data is embedded into
24
     *        proper place in SOAP Header. The key must be tag name and value
25
     *        tag value.
26
     */
27
    public function __construct($reference)
28
    {
29
        $elements = [
30
            new FragmentInjection(
31
                'http://schemas.xmlsoap.org/soap/envelope/',
32
                'Header',
33
                '<repr:representedParty xmlns:repr="http://x-road.eu/xsd/representation.xsd"/>'
34
            ),
35
        ];
36
37
        foreach ($reference as $name => $value) {
38
            $elements[] = new DOMElementInjection(
39
                'http://x-road.eu/xsd/representation.xsd',
40
                'representedParty',
41
                new \DOMElement($name, $value, 'http://x-road.eu/xsd/representation.xsd')
42
            );
43
        }
44
45
        parent::__construct(...$elements);
46
    }
47
}
48