ClientReference::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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