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

Service   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 30
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 22 2
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