PassengerTypeQuantity::withQuantity()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 8
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 PassengerTypeQuantity implements ValueObjectInterface
9
{
10
    public const PASSENGER_TYPE_ADULT = 'adult';
11
    public const PASSENGER_TYPE_CHILD = 'child';
12
    public const PASSENGER_TYPE_INFANT = 'infant';
13
14
    private static $passengerTypeEnum = ['adult', 'child', 'infant'];
15
16
    private $quantities;
17
18
    public function __construct()
19
    {
20
        $this->quantities = [];
21
    }
22
23
    public function withQuantity(string $passengerTye, int $quantity) : PassengerTypeQuantity
24
    {
25
        $this->checkPassengerType($passengerTye);
26
        $this->quantities[] = [
27
            'Code' => $passengerTye,
28
            'Quantity' => $quantity
29
        ];
30
        return $this;
31
    }
32
33
    private function checkPassengerType(string $checkPassengerType) : void
34
    {
35
        if (!\in_array($checkPassengerType, self::$passengerTypeEnum, true)) {
36
            throw new InvalidArgumentException(
37
                'Invalid PassengerTypeQuantity.Code value provided. Must be one of these: ' .
38
                implode(', ', self::$passengerTypeEnum)
39
            );
40
        }
41
    }
42
43
    public function getValue() : array
44
    {
45
        return $this->quantities;
46
    }
47
}
48