Completed
Push — master ( eb575e...c103e9 )
by Romain
13s
created

AirlineItineraryTemplate::setTax()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\Message\Attachment\Template;
6
7
use Kerox\Messenger\Model\Message\Attachment\Template;
8
9
class AirlineItineraryTemplate extends AbstractAirlineTemplate
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $introMessage;
15
16
    /**
17
     * @var string
18
     */
19
    protected $pnrNumber;
20
21
    /**
22
     * @var \Kerox\Messenger\Model\Message\Attachment\Template\Airline\PassengerInfo[]
23
     */
24
    protected $passengerInfo;
25
26
    /**
27
     * @var \Kerox\Messenger\Model\Message\Attachment\Template\Airline\ExtendedFlightInfo[]
28
     */
29
    protected $flightInfo;
30
31
    /**
32
     * @var \Kerox\Messenger\Model\Message\Attachment\Template\Airline\PassengerSegmentInfo[]
33
     */
34
    protected $passengerSegmentInfo;
35
36
    /**
37
     * @var array
38
     */
39
    protected $priceInfo = [];
40
41
    /**
42
     * @var null|string
43
     */
44
    protected $basePrice;
45
46
    /**
47
     * @var null|string
48
     */
49
    protected $tax;
50
51
    /**
52
     * @var string
53
     */
54
    protected $totalPrice;
55
56
    /**
57
     * @var string
58
     */
59
    protected $currency;
60
61
    /**
62
     * AirlineItinerary constructor.
63
     *
64
     * @param string                                                                            $introMessage
65
     * @param string                                                                            $locale
66
     * @param string                                                                            $pnrNumber
67
     * @param \Kerox\Messenger\Model\Message\Attachment\Template\Airline\PassengerInfo[]        $passengerInfo
68
     * @param \Kerox\Messenger\Model\Message\Attachment\Template\Airline\ExtendedFlightInfo[]   $flightInfo
69
     * @param \Kerox\Messenger\Model\Message\Attachment\Template\Airline\PassengerSegmentInfo[] $passengerSegmentInfo
70
     * @param string                                                                            $totalPrice
71
     * @param string                                                                            $currency
72
     */
73
    public function __construct(
74
        string $introMessage,
75
        string $locale,
76
        string $pnrNumber,
77
        array $passengerInfo,
78
        array $flightInfo,
79
        array $passengerSegmentInfo,
80
        string $totalPrice,
81
        string $currency
82
    ) {
83
        parent::__construct($locale);
84
85
        $this->introMessage = $introMessage;
86
        $this->pnrNumber = $pnrNumber;
87
        $this->passengerInfo = $passengerInfo;
88
        $this->flightInfo = $flightInfo;
89
        $this->passengerSegmentInfo = $passengerSegmentInfo;
90
        $this->totalPrice = $totalPrice;
91
        $this->currency = $currency;
92
    }
93
94
    /**
95
     * @param string $introMessage
96
     * @param string $locale
97
     * @param string $pnrNumber
98
     * @param array  $passengerInfo
99
     * @param array  $flightInfo
100
     * @param array  $passengerSegmentInfo
101
     * @param string $totalPrice
102
     * @param string $currency
103
     *
104
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\AirlineItineraryTemplate
105
     */
106
    public static function create(
107
        string $introMessage,
108
        string $locale,
109
        string $pnrNumber,
110
        array $passengerInfo,
111
        array $flightInfo,
112
        array $passengerSegmentInfo,
113
        string $totalPrice,
114
        string $currency
115
    ): self {
116
        return new self(
117
            $introMessage,
118
            $locale,
119
            $pnrNumber,
120
            $passengerInfo,
121
            $flightInfo,
122
            $passengerSegmentInfo,
123
            $totalPrice,
124
            $currency
125
        );
126
    }
127
128
    /**
129
     * @param string $title
130
     * @param string $amount
131
     * @param string $currency
132
     *
133
     * @throws \InvalidArgumentException
134
     *
135
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\AirlineItineraryTemplate
136
     */
137
    public function addPriceInfo(string $title, string $amount, ?string $currency = null): self
138
    {
139
        if ($currency !== null) {
140
            $this->isValidCurrency($currency);
141
        }
142
143
        $priceInfo = [
144
            'title'    => $title,
145
            'amount'   => $amount,
146
            'currency' => $currency,
147
        ];
148
149
        $this->isValidArray($this->priceInfo, 4);
150
151
        $this->priceInfo[] = array_filter($priceInfo);
152
153
        return $this;
154
    }
155
156
    /**
157
     * @param string $basePrice
158
     *
159
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\AirlineItineraryTemplate
160
     */
161
    public function setBasePrice(string $basePrice): self
162
    {
163
        $this->basePrice = $basePrice;
164
165
        return $this;
166
    }
167
168
    /**
169
     * @param string $tax
170
     *
171
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\AirlineItineraryTemplate
172
     */
173
    public function setTax(string $tax): self
174
    {
175
        $this->tax = $tax;
176
177
        return $this;
178
    }
179
180
    /**
181
     * @return array
182
     */
183
    public function toArray(): array
184
    {
185
        $array = parent::toArray();
186
        $array += [
187
            'payload' => [
188
                'template_type'          => Template::TYPE_AIRLINE_ITINERARY,
189
                'intro_message'          => $this->introMessage,
190
                'locale'                 => $this->locale,
191
                'theme_color'            => $this->themeColor,
192
                'pnr_number'             => $this->pnrNumber,
193
                'passenger_info'         => $this->passengerInfo,
194
                'flight_info'            => $this->flightInfo,
195
                'passenger_segment_info' => $this->passengerSegmentInfo,
196
                'price_info'             => $this->priceInfo,
197
                'base_price'             => $this->basePrice,
198
                'tax'                    => $this->tax,
199
                'total_price'            => $this->totalPrice,
200
                'currency'               => $this->currency,
201
            ],
202
        ];
203
204
        return $this->arrayFilter($array);
205
    }
206
}
207