Location::getValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
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
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