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

ClientReference::getIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 10
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Raigu\XRoad\SoapEnvelope;
4
5
use IteratorAggregate;
6
7
/**
8
 * I am a reference of a Client in string format acting as an iterator.
9
 *
10
 * I expose name and value used in SOAP envelope.
11
 */
12
final class ClientReference implements IteratorAggregate
13
{
14
    /**
15
     * @var string[]
16
     */
17
    private $parts;
18
19 1
    public function getIterator()
20
    {
21 1
        yield from array_combine(
22
            [
23 1
                'xRoadInstance',
24
                'memberClass',
25
                'memberCode',
26
                'subsystemCode',
27
            ],
28 1
            $this->parts
29
        );
30 1
    }
31
32
    /**
33
     * @param string $reference reference to the client.
34
     *                   Format: {xRoadInstance}/{memberClass/{memberCode}/{subsystemCode}
35
     *                   Example: EE/COM/00000000/sys
36
     */
37 2
    public function __construct(string $reference)
38
    {
39 2
        $parts = explode('/', $reference);
40 2
        if (count($parts) !== 4) {
41 1
            throw new \Exception('Could not extract client parameters. Invalid format.');
42
        }
43
44 1
        $this->parts = $parts;
45 1
    }
46
}
47