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

ServiceReference::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
c 1
b 0
f 0
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