RepresentedPartyReference::getIterator()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Raigu\XRoad\SoapEnvelope;
4
5
use IteratorAggregate;
6
7
/**
8
 * I am a string representation of a represented party.
9
 *
10
 * I act like iterator over associative array.
11
 * Returned array keys are same as tag names in SOAP envelope header.
12
 *
13
 * Represented party is the party on behalf of whom the client makes requests.
14
 * @see https://x-tee.ee/docs/live/xroad/pr-third_party_representation_extension.html
15
 */
16
final class RepresentedPartyReference implements IteratorAggregate
17
{
18
    /**
19
     * @var string[]
20
     */
21
    private $parts;
22
23
    public function getIterator()
24
    {
25
        if (count($this->parts) == 2) {
26
            yield 'partyClass' => $this->parts[0];
27
        }
28
29
        yield 'partyCode' => $this->parts[count($this->parts)-1];
30
    }
31
32
    /**
33
     * @see https://x-tee.ee/docs/live/xroad/pr-third_party_representation_extension.html
34
     * @param string $reference reference of a party who is represented by client.
35
     *       format: [{partyClass}/]{partyCode}
36
     * @param string $reference
37
     */
38
    public function __construct(string $reference)
39
    {
40
        $this->parts = explode('/', $reference, 2);
41
    }
42
}
43