FareOptions::addPriceType()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 4
nop 1
1
<?php
2
/**
3
 * amadeus-ws-client
4
 *
5
 * Copyright 2015 Amadeus Benelux NV
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 *
19
 * @package Amadeus
20
 * @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
21
 */
22
23
namespace Amadeus\Client\Struct\Fare\MasterPricer;
24
25
use Amadeus\Client\RequestOptions\Fare\MPTicketingPriceScheme;
26
use Amadeus\Client\RequestOptions\Fare\MPFeeId;
27
28
/**
29
 * FareOptions
30
 *
31
 * @package Amadeus\Client\Struct\Fare\MasterPricer
32
 * @author Dieter Devlieghere <[email protected]>
33
 */
34
class FareOptions
35
{
36
    /**
37
     * @var PricingTickInfo
38
     */
39
    public $pricingTickInfo;
40
    /**
41
     * @var Corporate
42
     */
43
    public $corporate;
44
    /**
45
     * @var TicketingPriceScheme
46
     */
47
    public $ticketingPriceScheme;
48
    /**
49
     * @var FeeIdDescription
50
     */
51
    public $feeIdDescription;
52
    /**
53
     * @var ConversionRate
54
     */
55
    public $conversionRate;
56
    /**
57
     * @var FormOfPaymentDetails[]|array
58
     */
59
    public $formOfPayment;
60
61
    public $frequentTravellerInfo;
62
63
    public $monetaryCabinInfo;
64
65
    public $multiTicket;
66
67
    /**
68
     * FareOptions constructor.
69
     *
70
     * @param array $flightOptions List of flight / fare options
71
     * @param array $corpCodesUniFares list of Corporate codes for Corporate Unifares
72
     * @param bool $tickPreCheck Do Ticketability pre-check?
73
     * @param string|null $currency Override Currency conversion
74
     * @param MPFeeId[]|null $feeIds List of FeeIds
75
     * @param string|null Corporate qualifier for Corporate Unifares
76
     * @param $multiTicket
77
     * @param MPTicketingPriceScheme|null $ticketingPriceScheme
78
     * @param array|null $formOfPayment
79
     */
80
    public function __construct(
81
        array $flightOptions,
82
        array $corpCodesUniFares,
83
        $tickPreCheck,
84
        $currency,
85
        $feeIds,
86
        $corporateQualifier,
87
        $multiTicket,
88
        $ticketingPriceScheme,
89
        $formOfPayment
90
    ) {
91
        if ($tickPreCheck === true) {
92
            $this->addPriceType(PricingTicketing::PRICETYPE_TICKETABILITY_PRECHECK);
93
        }
94
95
        foreach ($flightOptions as $flightOption) {
96
            $this->addPriceType($flightOption);
97
98
            if ($flightOption === PricingTicketing::PRICETYPE_CORPORATE_UNIFARES) {
99
                $this->corporate = new Corporate();
100
                $this->corporate->corporateId[] = new CorporateId($corpCodesUniFares, $corporateQualifier);
101
            }
102
        }
103
104
        $this->loadCurrencyOverride($currency);
105
        $this->loadMultiTicket($multiTicket);
106
        if (!is_null($feeIds)) {
107
            $this->loadFeeIds($feeIds);
108
        }
109
        if (!is_null($ticketingPriceScheme)) {
110
            $this->loadTicketingPriceScheme($ticketingPriceScheme);
111
        }
112
        if (!is_null($formOfPayment) && count($formOfPayment)) {
113
            $this->loadFormOfPayment($formOfPayment);
114
        }
115
    }
116
117
    /**
118
     * Set fee ids if needed
119
     *
120
     * @param MPFeeId[] $feeIds
121
     */
122
    protected function loadFeeIds($feeIds)
123
    {
124
        if (is_null($this->feeIdDescription)) {
125
            $this->feeIdDescription = new FeeIdDescription();
126
        }
127
        foreach ($feeIds as $feeId) {
128
            $this->feeIdDescription->feeId[] = new FeeId($feeId->type, $feeId->number);
129
        }
130
    }
131
132
    /**
133
     * Set currency override code if needed
134
     *
135
     * @param string|null $currency
136
     */
137
    protected function loadCurrencyOverride($currency)
138
    {
139
        if (is_string($currency) && strlen($currency) === 3) {
140
            $this->addPriceType(PricingTicketing::PRICETYPE_OVERRIDE_CURRENCY_CONVERSION);
141
142
            $this->conversionRate = new ConversionRate($currency);
143
        }
144
    }
145
146
    /**
147
     * Set multi ticket on if needed
148
     *
149
     * @param string|null $multiTicket
150
     */
151
    protected function loadMultiTicket($multiTicket)
152
    {
153
        if ($multiTicket) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $multiTicket of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
154
            $this->addPriceType(PricingTicketing::PRICETYPE_MULTI_TICKET);
155
        }
156
    }
157
158
    /**
159
     * Add PriceType
160
     *
161
     * @param string $type
162
     */
163
    protected function addPriceType($type)
164
    {
165
        if (is_null($this->pricingTickInfo)) {
166
            $this->pricingTickInfo = new PricingTickInfo();
167
        }
168
        if (is_null($this->pricingTickInfo->pricingTicketing)) {
169
            $this->pricingTickInfo->pricingTicketing = new PricingTicketing();
170
        }
171
172
        $this->pricingTickInfo->pricingTicketing->priceType[] = $type;
173
    }
174
175
    protected function loadTicketingPriceScheme($ticketingPriceScheme)
176
    {
177
        $priceScheme = new TicketingPriceScheme();
178
        $priceScheme->referenceNumber = $ticketingPriceScheme->referenceNumber;
179
        $priceScheme->name = $ticketingPriceScheme->name;
180
        $priceScheme->status = $ticketingPriceScheme->status;
181
        $priceScheme->description = $ticketingPriceScheme->description;
182
        $this->ticketingPriceScheme = $priceScheme;
183
    }
184
185
    protected function loadFormOfPayment(array $formOfPayment)
186
    {
187
        /** @var \Amadeus\Client\RequestOptions\Fare\MasterPricer\FormOfPaymentDetails $fop */
188
        foreach ($formOfPayment as $fop) {
189
            $this->formOfPayment[] = new FormOfPaymentDetails(
190
                $fop->type,
191
                $fop->chargedAmount,
192
                $fop->creditCardNumber
193
            );
194
        }
195
    }
196
}
197