Completed
Push — master ( f191f2...2cc3ee )
by Dieter
09:10
created

FareOptions::loadTicketingPriceScheme()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
ccs 8
cts 8
cp 1
rs 9.6666
cc 1
eloc 7
nc 1
nop 1
crap 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\MasterPricer\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
    public $formOfPayment;
58
59
    public $frequentTravellerInfo;
60
61
    public $monetaryCabinInfo;
62
63
    public $multiTicket;
64
65
    /**
66
     * FareOptions constructor.
67
     *
68
     * @param array $flightOptions List of flight / fare options
69
     * @param array $corpCodesUniFares list of Corporate codes for Corporate Unifares
70
     * @param bool $tickPreCheck Do Ticketability pre-check?
71
     * @param string|null $currency Override Currency conversion
72
     * @param MPFeeId[]|null $feeIds List of FeeIds
73
     * @param string|null Corporate qualifier for Corporate Unifares
74
     * @param $multiTicket
75
     * @param MPTicketingPriceScheme|null $ticketingPriceScheme
76
     */
77 48
    public function __construct(
78
        array $flightOptions,
79
        array $corpCodesUniFares,
80
        $tickPreCheck,
81
        $currency,
82
        $feeIds,
83
        $corporateQualifier,
84
        $multiTicket,
85
        $ticketingPriceScheme
86
    ) {
87 48
        if ($tickPreCheck === true) {
88 4
            $this->addPriceType(PricingTicketing::PRICETYPE_TICKETABILITY_PRECHECK);
89 2
        }
90
91 48
        foreach ($flightOptions as $flightOption) {
92 28
            $this->addPriceType($flightOption);
93
94 28
            if ($flightOption === PricingTicketing::PRICETYPE_CORPORATE_UNIFARES) {
95 12
                $this->corporate = new Corporate();
96 20
                $this->corporate->corporateId[] = new CorporateId($corpCodesUniFares, $corporateQualifier);
97 6
            }
98 24
        }
99
100 48
        $this->loadCurrencyOverride($currency);
101 48
        $this->loadMultiTicket($multiTicket);
102 48
        if (!is_null($feeIds)) {
103 4
            $this->loadFeeIds($feeIds);
104 2
        }
105 48
        if (!is_null($ticketingPriceScheme)) {
106 4
            $this->loadTicketingPriceScheme($ticketingPriceScheme);
107 2
        }
108 48
    }
109
110
    /**
111
     * Set fee ids if needed
112
     *
113
     * @param MPFeeId[] $feeIds
114
     */
115 4
    protected function loadFeeIds($feeIds)
116
    {
117 4
        if (is_null($this->feeIdDescription)) {
118 4
            $this->feeIdDescription = new FeeIdDescription();
119 2
        }
120 4
        foreach ($feeIds as $feeId) {
121 4
            $this->feeIdDescription->feeId[] = new FeeId($feeId->type, $feeId->number);
122 2
        }
123 4
    }
124
125
    /**
126
     * Set currency override code if needed
127
     *
128
     * @param string|null $currency
129
     */
130 48
    protected function loadCurrencyOverride($currency)
131
    {
132 48
        if (is_string($currency) && strlen($currency) === 3) {
133 4
            $this->addPriceType(PricingTicketing::PRICETYPE_OVERRIDE_CURRENCY_CONVERSION);
134
135 4
            $this->conversionRate = new ConversionRate($currency);
136 2
        }
137 48
    }
138
139
    /**
140
     * Set multi ticket on if needed
141
     *
142
     * @param string|null $multiTicket
143
     */
144 48
    protected function loadMultiTicket($multiTicket)
145
    {
146 48
        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...
147 4
            $this->addPriceType(PricingTicketing::PRICETYPE_MULTI_TICKET);
148 2
        }
149 48
    }
150
151
    /**
152
     * Add PriceType
153
     *
154
     * @param string $type
155
     */
156 40
    protected function addPriceType($type)
157
    {
158 40
        if (is_null($this->pricingTickInfo)) {
159 40
            $this->pricingTickInfo = new PricingTickInfo();
160 20
        }
161 40
        if (is_null($this->pricingTickInfo->pricingTicketing)) {
162 40
            $this->pricingTickInfo->pricingTicketing = new PricingTicketing();
163 20
        }
164
165 40
        $this->pricingTickInfo->pricingTicketing->priceType[] = $type;
166 40
    }
167
168 4
    protected function loadTicketingPriceScheme($ticketingPriceScheme)
169
    {
170 4
        $priceScheme = new TicketingPriceScheme();
171 4
        $priceScheme->referenceNumber = $ticketingPriceScheme->referenceNumber;
172 4
        $priceScheme->name = $ticketingPriceScheme->name;
173 4
        $priceScheme->status = $ticketingPriceScheme->status;
174 4
        $priceScheme->description = $ticketingPriceScheme->description;
175 4
        $this->ticketingPriceScheme = $priceScheme;
176 4
    }
177
}
178