Completed
Push — master ( c270ad...b8baec )
by Dieter
14:46 queued 06:10
created

FareOptions::loadMultiTicket()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
crap 2
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\MPFeeId;
26
27
/**
28
 * FareOptions
29
 *
30
 * @package Amadeus\Client\Struct\Fare\MasterPricer
31
 * @author Dieter Devlieghere <[email protected]>
32
 */
33
class FareOptions
34
{
35
    /**
36
     * @var PricingTickInfo
37
     */
38
    public $pricingTickInfo;
39
    /**
40
     * @var Corporate
41
     */
42
    public $corporate;
43
44
    public $ticketingPriceScheme;
45
    /**
46
     * @var FeeIdDescription
47
     */
48
    public $feeIdDescription;
49
    /**
50
     * @var ConversionRate
51
     */
52
    public $conversionRate;
53
54
    public $formOfPayment;
55
56
    public $frequentTravellerInfo;
57
58
    public $monetaryCabinInfo;
59
60
    public $multiTicket;
61
62
    /**
63
     * FareOptions constructor.
64
     *
65
     * @param array $flightOptions List of flight / fare options
66
     * @param array $corpCodesUniFares list of Corporate codes for Corporate Unifares
67
     * @param bool $tickPreCheck Do Ticketability pre-check?
68
     * @param string|null $currency Override Currency conversion
69
     * @param MPFeeId[]|null $feeIds List of FeeIds
70
     * @param string|null Corporate qualifier for Corporate Unifares
71
     */
72 11
    public function __construct(
73
        array $flightOptions,
74
        array $corpCodesUniFares,
75
        $tickPreCheck,
76
        $currency,
77
        $feeIds,
78
        $corporateQualifier,
79
        $multiTicket
80
    ) {
81 11
        if ($tickPreCheck === true) {
82 1
            $this->addPriceType(PricingTicketing::PRICETYPE_TICKETABILITY_PRECHECK);
83 1
        }
84
85 11
        foreach ($flightOptions as $flightOption) {
86 7
            $this->addPriceType($flightOption);
87
88 7
            if ($flightOption === PricingTicketing::PRICETYPE_CORPORATE_UNIFARES) {
89 3
                $this->corporate = new Corporate();
90 3
                $this->corporate->corporateId[] = new CorporateId($corpCodesUniFares, $corporateQualifier);
91 3
            }
92 11
        }
93
94 11
        $this->loadCurrencyOverride($currency);
95 11
        $this->loadMultiTicket($multiTicket);
96 11
        if (!is_null($feeIds)) {
97 1
            $this->loadFeeIds($feeIds);
98 1
        }
99 11
    }
100
101
    /**
102
     * Set fee ids if needed
103
     *
104
     * @param MPFeeId[] $feeIds
105
     */
106 1
    protected function loadFeeIds($feeIds)
107
    {
108 1
        if (is_null($this->feeIdDescription)) {
109 1
            $this->feeIdDescription = new FeeIdDescription();
110 1
        }
111 1
        foreach ($feeIds as $feeId) {
112 1
            $this->feeIdDescription->feeId[] = new FeeId($feeId->type, $feeId->number);
113 1
        }
114 1
    }
115
116
    /**
117
     * Set currency override code if needed
118
     *
119
     * @param string|null $currency
120
     */
121 11
    protected function loadCurrencyOverride($currency)
122
    {
123 11
        if (is_string($currency) && strlen($currency) === 3) {
124 1
            $this->addPriceType(PricingTicketing::PRICETYPE_OVERRIDE_CURRENCY_CONVERSION);
125
126 1
            $this->conversionRate = new ConversionRate($currency);
127 1
        }
128 11
    }
129
130
    /**
131
     * Set multi ticket on if needed
132
     *
133
     * @param string|null $currency
0 ignored issues
show
Bug introduced by
There is no parameter named $currency. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
134
     */
135 11
    protected function loadMultiTicket($multiTicket)
136
    {
137 11
        if ($multiTicket) {
138 1
            $this->addPriceType(PricingTicketing::PRICETYPE_MULTI_TICKET);
139 1
        }
140 11
    }
141
142
    /**
143
     * Add PriceType
144
     *
145
     * @param string $type
146
     */
147 10
    protected function addPriceType($type)
148
    {
149 10
        if (is_null($this->pricingTickInfo)) {
150 10
            $this->pricingTickInfo = new PricingTickInfo();
151 10
        }
152 10
        if (is_null($this->pricingTickInfo->pricingTicketing)) {
153 10
            $this->pricingTickInfo->pricingTicketing = new PricingTicketing();
154 10
        }
155
156 10
        $this->pricingTickInfo->pricingTicketing->priceType[] = $type;
157 10
    }
158
}
159