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

ServiceReference   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getIterator() 0 12 1
A __construct() 0 8 2
1
<?php
2
3
namespace Raigu\XRoad\SoapEnvelope;
4
5
/**
6
 * I am a reference of a service in string format acting as an iterator.
7
 *
8
 * I expose name and value used in SOAP envelope.
9
 */
10
final class ServiceReference implements \IteratorAggregate
11
{
12
    /**
13
     * @var string[]
14
     */
15
    private $parts;
16
17 1
    public function getIterator()
18
    {
19 1
        yield from array_combine(
20
            [
21 1
                'xRoadInstance',
22
                'memberClass',
23
                'memberCode',
24
                'subsystemCode',
25
                'serviceCode',
26
                'serviceVersion',
27
            ],
28 1
            $this->parts
29
        );
30 1
    }
31
32
    /**
33
     * @param string $reference reference to the serice.
34
     *                   Format: {xRoadInstance}/{memberClass/{memberCode}/{subsystemCode}/{serviceCode}/{serviceVerson}
35
     *                   Example: EE/GOV/70000310/DHX.Riigi-Teataja/sendDocument/v1
36
     */
37 2
    public function __construct(string $reference)
38
    {
39 2
        $parts = explode('/', $reference);
40 2
        if (count($parts) !== 6) {
41 1
            throw new \Exception('Could not extract service parameters. Invalid format.');
42
        }
43
44 1
        return $this->parts = $parts;
45
    }
46
}
47