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

ServiceReference::getIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 12
ccs 4
cts 4
cp 1
crap 1
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