Service::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

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