GetFareFamilyListParameters   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A withMilesRequest() 0 4 1
A withAirportIataCode() 0 5 1
A checkPortIataCode() 0 6 2
A __construct() 0 3 1
A getValue() 0 5 1
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