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

RepresentedPartyReference::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
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 represented party in string format acting as an iterator.
9
 *
10
 * I expose name and value used in SOAP envelope.
11
 *
12
 * Represented party is the party on behalf of whom the client makes requests.
13
 * @see https://x-tee.ee/docs/live/xroad/pr-third_party_representation_extension.html
14
 */
15
final class RepresentedPartyReference implements IteratorAggregate
16
{
17
    /**
18
     * @var string[]
19
     */
20
    private $parts;
21
22 1
    public function getIterator()
23
    {
24 1
        if (count($this->parts) == 2) {
25 1
            yield 'partyClass' => $this->parts[0];
26
        }
27
28 1
        yield 'partyCode' => $this->parts[count($this->parts)-1];
29 1
    }
30
31
    /**
32
     * @see https://x-tee.ee/docs/live/xroad/pr-third_party_representation_extension.html
33
     * @param string $reference reference of a party who is represented by client.
34
     *       format: [{partyClass}/]{partyCode}
35
     * @param string $reference
36
     */
37 1
    public function __construct(string $reference)
38
    {
39 1
        $this->parts = explode('/', $reference, 2);
40 1
    }
41
}
42