Client::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 13
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 21
rs 9.8333
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 an X-Road client description.
12
 *
13
 * I can inject myself into SOAP envelope header
14
 */
15
final class Client extends AbstractElement
16
{
17
18
    /**
19
     * @param Traversable|array $reference associative array of data describing
20
     *        client who is making the X-Road request. Data is embedded into
21
     *        proper place in SOAP Header. The key must be tag name and value
22
     *        tag value.
23
     */
24
    public function __construct($reference)
25
    {
26
        $elements = [
27
            new FragmentInjection(
28
                'http://schemas.xmlsoap.org/soap/envelope/',
29
                'Header',
30
                '<xrd:client xmlns:xrd="http://x-road.eu/xsd/xroad.xsd" ' .
31
                'xmlns:id="http://x-road.eu/xsd/identifiers" ' .
32
                'id:objectType="SUBSYSTEM"/>'
33
            ),
34
        ];
35
36
        foreach ($reference as $name => $value) {
37
            $elements[] = new DOMElementInjection(
38
                'http://x-road.eu/xsd/xroad.xsd',
39
                'client',
40
                new \DOMElement($name, $value, 'http://x-road.eu/xsd/identifiers')
41
            );
42
        }
43
44
        parent::__construct(...$elements);
45
    }
46
}
47