Location   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A changeLocationCode() 0 10 2
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
final class Location implements ValueObjectInterface
9
{
10
    public const MULTIPLE_AIRPORT_TRUE = true;
11
    public const MULTIPLE_AIRPORT_FALSE = false;
12
13
    private $locationCode;
14
    private $multiAirportCityInd;
15
16
    public function __construct(string $locationCode, bool $multiAirportCityInd)
17
    {
18
        $this->multiAirportCityInd = $multiAirportCityInd;
19
        $this->changeLocationCode($locationCode);
20
    }
21
22
    private function changeLocationCode(string $locationCode) : void
23
    {
24
        if (!preg_match('/^[A-Z]{3}$/', $locationCode)) {
25
            {
26
                throw new InvalidArgumentException(
27
                    'Invalid OriginLocation.LocationCode value provided. Valid IATA code must be used'
28
                );
29
            }
30
        }
31
        $this->locationCode = $locationCode;
32
    }
33
34
    public function getValue() : array
35
    {
36
        return [
37
            'LocationCode' => $this->locationCode,
38
            'MultiAirportCityInd' => $this->multiAirportCityInd
39
        ];
40
    }
41
}
42