ServiceReference   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 35
rs 10
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 string representation of an X-Road service.
7
 *
8
 * I act like iterator over associative array.
9
 * Returned array keys are same as tag names in SOAP envelope header.
10
 */
11
final class ServiceReference implements \IteratorAggregate
12
{
13
    /**
14
     * @var string[]
15
     */
16
    private $parts;
17
18
    public function getIterator()
19
    {
20
        yield from array_combine(
21
            [
22
                'xRoadInstance',
23
                'memberClass',
24
                'memberCode',
25
                'subsystemCode',
26
                'serviceCode',
27
                'serviceVersion',
28
            ],
29
            $this->parts
30
        );
31
    }
32
33
    /**
34
     * @param string $reference reference to the serice.
35
     *                   Format: {xRoadInstance}/{memberClass/{memberCode}/{subsystemCode}/{serviceCode}/{serviceVerson}
36
     *                   Example: EE/GOV/70000310/DHX.Riigi-Teataja/sendDocument/v1
37
     */
38
    public function __construct(string $reference)
39
    {
40
        $parts = explode('/', $reference);
41
        if (count($parts) !== 6) {
42
            throw new \Exception('Could not extract service parameters. Invalid format.');
43
        }
44
45
        return $this->parts = $parts;
46
    }
47
}
48