Completed
Push — master ( 06408e...753060 )
by Dieter
12:23 queued 05:07
created

FareOptions::__construct()   B

Complexity

Conditions 8
Paths 48

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 8

Importance

Changes 0
Metric Value
dl 0
loc 36
c 0
b 0
f 0
ccs 23
cts 23
cp 1
rs 8.0995
cc 8
nc 48
nop 9
crap 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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 52
    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 52
        if ($tickPreCheck === true) {
92 4
            $this->addPriceType(PricingTicketing::PRICETYPE_TICKETABILITY_PRECHECK);
93 2
        }
94
95 52
        foreach ($flightOptions as $flightOption) {
96 28
            $this->addPriceType($flightOption);
97
98 28
            if ($flightOption === PricingTicketing::PRICETYPE_CORPORATE_UNIFARES) {
99 12
                $this->corporate = new Corporate();
100 20
                $this->corporate->corporateId[] = new CorporateId($corpCodesUniFares, $corporateQualifier);
101 6
            }
102 26
        }
103
104 52
        $this->loadCurrencyOverride($currency);
105 52
        $this->loadMultiTicket($multiTicket);
106 52
        if (!is_null($feeIds)) {
107 4
            $this->loadFeeIds($feeIds);
108 2
        }
109 52
        if (!is_null($ticketingPriceScheme)) {
110 4
            $this->loadTicketingPriceScheme($ticketingPriceScheme);
111 2
        }
112 52
        if (!is_null($formOfPayment) && count($formOfPayment)) {
113 4
            $this->loadFormOfPayment($formOfPayment);
114 2
        }
115 52
    }
116
117
    /**
118
     * Set fee ids if needed
119
     *
120
     * @param MPFeeId[] $feeIds
121
     */
122 4
    protected function loadFeeIds($feeIds)
123
    {
124 4
        if (is_null($this->feeIdDescription)) {
125 4
            $this->feeIdDescription = new FeeIdDescription();
126 2
        }
127 4
        foreach ($feeIds as $feeId) {
128 4
            $this->feeIdDescription->feeId[] = new FeeId($feeId->type, $feeId->number);
129 2
        }
130 4
    }
131
132
    /**
133
     * Set currency override code if needed
134
     *
135
     * @param string|null $currency
136
     */
137 52
    protected function loadCurrencyOverride($currency)
138
    {
139 52
        if (is_string($currency) && strlen($currency) === 3) {
140 4
            $this->addPriceType(PricingTicketing::PRICETYPE_OVERRIDE_CURRENCY_CONVERSION);
141
142 4
            $this->conversionRate = new ConversionRate($currency);
143 2
        }
144 52
    }
145
146
    /**
147
     * Set multi ticket on if needed
148
     *
149
     * @param string|null $multiTicket
150
     */
151 52
    protected function loadMultiTicket($multiTicket)
152
    {
153 52
        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 4
            $this->addPriceType(PricingTicketing::PRICETYPE_MULTI_TICKET);
155 2
        }
156 52
    }
157
158
    /**
159
     * Add PriceType
160
     *
161
     * @param string $type
162
     */
163 40
    protected function addPriceType($type)
164
    {
165 40
        if (is_null($this->pricingTickInfo)) {
166 40
            $this->pricingTickInfo = new PricingTickInfo();
167 20
        }
168 40
        if (is_null($this->pricingTickInfo->pricingTicketing)) {
169 40
            $this->pricingTickInfo->pricingTicketing = new PricingTicketing();
170 20
        }
171
172 40
        $this->pricingTickInfo->pricingTicketing->priceType[] = $type;
173 40
    }
174
175 4
    protected function loadTicketingPriceScheme($ticketingPriceScheme)
176
    {
177 4
        $priceScheme = new TicketingPriceScheme();
178 4
        $priceScheme->referenceNumber = $ticketingPriceScheme->referenceNumber;
179 4
        $priceScheme->name = $ticketingPriceScheme->name;
180 4
        $priceScheme->status = $ticketingPriceScheme->status;
181 4
        $priceScheme->description = $ticketingPriceScheme->description;
182 4
        $this->ticketingPriceScheme = $priceScheme;
183 4
    }
184
185 4
    protected function loadFormOfPayment(array $formOfPayment)
186
    {
187
        /** @var \Amadeus\Client\RequestOptions\Fare\MasterPricer\FormOfPaymentDetails $fop */
188 4
        foreach ($formOfPayment as $fop) {
189 4
            $this->formOfPayment[] = new FormOfPaymentDetails(
190 4
                $fop->type,
191 4
                $fop->chargedAmount,
192 4
                $fop->creditCardNumber
193 2
            );
194 2
        }
195 4
    }
196
}
197