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

Service::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

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