PassengerTypeQuantity   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A withQuantity() 0 8 1
A getValue() 0 3 1
A checkPassengerType() 0 6 2
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