Completed
Push — master ( 3347ae...8ec7fe )
by Romain
9s
created

ExtendedFlightInfo::getAllowedTravelClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
namespace Kerox\Messenger\Model\Message\Attachment\Template\Airline;
3
4
class ExtendedFlightInfo extends FlightInfo implements TravelClassInterface
5
{
6
7
    /**
8
     * @var string
9
     */
10
    protected $connectionId;
11
12
    /**
13
     * @var string
14
     */
15
    protected $segmentId;
16
17
    /**
18
     * @var string
19
     */
20
    protected $aircraftType;
21
22
    /**
23
     * @var string
24
     */
25
    protected $travelClass;
26
27
    /**
28
     * ExtendedFlightInfo constructor.
29
     *
30
     * @param string $connectionId
31
     * @param string $segmentId
32
     * @param string $flightNumber
33
     * @param \Kerox\Messenger\Model\Message\Attachment\Template\Airline\Airport $departureAirport
34
     * @param \Kerox\Messenger\Model\Message\Attachment\Template\Airline\Airport $arrivalAirport
35
     * @param \Kerox\Messenger\Model\Message\Attachment\Template\Airline\FlightSchedule $flightSchedule
36
     * @param string $travelClass
37
     */
38
    public function __construct(
39
        string $connectionId,
40
        string $segmentId,
41
        string $flightNumber,
42
        Airport $departureAirport,
43
        Airport $arrivalAirport,
44
        FlightSchedule $flightSchedule,
45
        string $travelClass
46
    ) {
47
        parent::__construct($flightNumber, $departureAirport, $arrivalAirport, $flightSchedule);
48
49
        $this->isValidTravelClass($travelClass);
50
51
        $this->connectionId = $connectionId;
52
        $this->segmentId = $segmentId;
53
        $this->travelClass = $travelClass;
54
    }
55
56
    /**
57
     * @param string $aircraftType
58
     * @return ExtendedFlightInfo
59
     */
60
    public function setAircraftType(string $aircraftType): ExtendedFlightInfo
61
    {
62
        $this->aircraftType = $aircraftType;
63
64
        return $this;
65
    }
66
67
    /**
68
     * @param string $travelClass
69
     * @return void
70
     * @throws \InvalidArgumentException
71
     */
72
    public function isValidTravelClass(string $travelClass)
73
    {
74
        $allowedTravelClass = $this->getAllowedTravelClass();
75
        if (!in_array($travelClass, $allowedTravelClass)) {
76
            throw new \InvalidArgumentException('$travelClass must be either ' . implode(', ', $allowedTravelClass));
77
        }
78
    }
79
80
    /**
81
     * @return array
82
     */
83
    public function getAllowedTravelClass(): array
84
    {
85
        return [
86
            self::ECONOMY,
87
            self::BUSINESS,
88
            self::FIRST_CLASS,
89
        ];
90
    }
91
92
    /**
93
     * @return array
94
     */
95
    public function jsonSerialize(): array
96
    {
97
        $json = [
98
            'connection_id' => $this->connectionId,
99
            'segment_id' => $this->segmentId,
100
            'flight_number' => $this->flightNumber,
101
            'aircraft_type' => $this->aircraftType,
102
            'travel_class' => $this->travelClass,
103
            'departure_airport' => $this->departureAirport,
104
            'arrival_airport' => $this->arrivalAirport,
105
            'flight_schedule' => $this->flightSchedule,
106
        ];
107
108
        return array_filter($json);
109
    }
110
}
111