GetFareFamilyListParameters::checkPortIataCode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace TK\API\ValueObject;
5
6
use TK\API\Exception\InvalidArgumentException;
7
8
class GetFareFamilyListParameters implements ValueObjectInterface
9
{
10
    private $portList;
11
    private $isMilesRequest = 'F';
12
13
    public function __construct()
14
    {
15
        $this->portList = [];
16
    }
17
18
    public function withAirportIataCode(string $portIataCode) : GetFareFamilyListParameters
19
    {
20
        $this->checkPortIataCode($portIataCode);
21
        $this->portList[] = $portIataCode;
22
        return $this;
23
    }
24
25
    private function checkPortIataCode(string $portIataCode) : void
26
    {
27
        if (!preg_match('/^[A-Z]{3}$/', $portIataCode)) {
28
            {
29
                throw new InvalidArgumentException(
30
                    'Invalid portList value provided. Valid IATA code must be used.'
31
                );
32
            }
33
        }
34
    }
35
36
    public function withMilesRequest() : GetFareFamilyListParameters
37
    {
38
        $this->isMilesRequest = 'T';
39
        return $this;
40
    }
41
42
    public function getValue() : array
43
    {
44
        return [
45
            'portList' => $this->portList,
46
            'isMilesRequest' => $this->isMilesRequest
47
        ];
48
    }
49
}
50