Completed
Branch develop (a0a623)
by Romain
02:33
created

ExtendedFlightInfo   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 106
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 1
A setAircraftType() 0 6 1
A isValidTravelClass() 0 7 2
A getAllowedTravelClass() 0 8 1
A jsonSerialize() 0 15 1
1
<?php
2
namespace Kerox\Messenger\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\Message\Attachment\Template\Airline\Airport $departureAirport
34
     * @param \Kerox\Messenger\Message\Attachment\Template\Airline\Airport $arrivalAirport
35
     * @param \Kerox\Messenger\Message\Attachment\Template\Airline\FlightSchedule $flightSchedule
36
     * @param string $travelClass
37
     */
38
    public function __construct(string $connectionId,
39
                                string $segmentId,
40
                                string $flightNumber,
41
                                Airport $departureAirport,
42
                                Airport $arrivalAirport,
43
                                FlightSchedule $flightSchedule,
44
                                string $travelClass
45
    ) {
46
        parent::__construct($flightNumber, $departureAirport, $arrivalAirport, $flightSchedule);
47
48
        $this->isValidTravelClass($travelClass);
49
50
        $this->connectionId = $connectionId;
51
        $this->segmentId = $segmentId;
52
        $this->travelClass = $travelClass;
53
    }
54
55
    /**
56
     * @param string $aircraftType
57
     * @return ExtendedFlightInfo
58
     */
59
    public function setAircraftType(string $aircraftType): ExtendedFlightInfo
60
    {
61
        $this->aircraftType = $aircraftType;
62
63
        return $this;
64
    }
65
66
    /**
67
     * @param string $travelClass
68
     * @return void
69
     * @throws \InvalidArgumentException
70
     */
71
    public function isValidTravelClass(string $travelClass)
72
    {
73
        $allowedTravelClass = $this->getAllowedTravelClass();
74
        if (!in_array($travelClass, $allowedTravelClass)) {
75
            throw new \InvalidArgumentException('Allowed values for $travelClass are: ' . implode(', ', $allowedTravelClass));
76
        }
77
    }
78
79
    /**
80
     * @return array
81
     */
82
    public function getAllowedTravelClass(): array
83
    {
84
        return [
85
            self::ECONOMY,
86
            self::BUSINESS,
87
            self::FIRST_CLASS,
88
        ];
89
    }
90
91
    /**
92
     * @return array
93
     */
94
    public function jsonSerialize(): array
95
    {
96
        $json = [
97
            'connection_id' => $this->connectionId,
98
            'segment_id' => $this->segmentId,
99
            'flight_number' => $this->flightNumber,
100
            'aircraft_type' => $this->aircraftType,
101
            'travel_class' => $this->travelClass,
102
            'departure_airport' => $this->departureAirport,
103
            'arrival_airport' => $this->arrivalAirport,
104
            'flight_schedule' => $this->flightSchedule,
105
        ];
106
107
        return array_filter($json);
108
    }
109
}
110