Completed
Push — master ( 7b19a2...92df1a )
by Dieter
05:10
created

FareOptions::addPriceType()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
ccs 9
cts 9
cp 1
rs 9.4285
cc 3
eloc 6
nc 4
nop 1
crap 3
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
/**
26
 * FareOptions
27
 *
28
 * @package Amadeus\Client\Struct\Fare\MasterPricer
29
 * @author Dieter Devlieghere <[email protected]>
30
 */
31
class FareOptions
32
{
33
    /**
34
     * @var PricingTickInfo
35
     */
36
    public $pricingTickInfo;
37
    /**
38
     * @var Corporate
39
     */
40
    public $corporate;
41
42
    public $ticketingPriceScheme;
43
    /**
44
     * @var FeeIdDescription
45
     */
46
    public $feeIdDescription;
47
    /**
48
     * @var ConversionRate
49
     */
50
    public $conversionRate;
51
52
    public $formOfPayment;
53
54
    public $frequentTravellerInfo;
55
56
    public $monetaryCabinInfo;
57
58
    /**
59
     * FareOptions constructor.
60
     *
61
     * @param array $flightOptions List of flight / fare options
62
     * @param array $corpCodesUniFares list of Corporate codes for Corporate Unifares
63
     * @param bool $tickPreCheck Do Ticketability pre-check?
64
     * @param string|null $currency Override Currency conversion
65
     */
66 4
    public function __construct(array $flightOptions, array $corpCodesUniFares, $tickPreCheck, $currency)
67
    {
68 4
        if ($tickPreCheck === true) {
69 1
            $this->addPriceType(PricingTicketing::PRICETYPE_TICKETABILITY_PRECHECK);
70 1
        }
71
72 4
        foreach ($flightOptions as $flightOption) {
73 2
            $this->addPriceType($flightOption);
74
75 2
            if ($flightOption === PricingTicketing::PRICETYPE_CORPORATE_UNIFARES) {
76 2
                $this->corporate = new Corporate();
77 2
                $this->corporate->corporateId[] = new CorporateId($corpCodesUniFares);
78 2
            }
79 4
        }
80
81 4
        $this->loadCurrencyOverride($currency);
82 4
    }
83
84
    /**
85
     * Set currency override code if needed
86
     *
87
     * @param string|null $currency
88
     */
89 4
    protected function loadCurrencyOverride($currency)
90
    {
91 4
        if (is_string($currency) && strlen($currency) === 3) {
92 1
            $this->addPriceType(PricingTicketing::PRICETYPE_OVERRIDE_CURRENCY_CONVERSION);
93
94 1
            $this->conversionRate = new ConversionRate($currency);
95 1
        }
96 4
    }
97
98
    /**
99
     * Add PriceType
100
     *
101
     * @param string $type
102
     */
103 4
    protected function addPriceType($type)
104
    {
105 4
        if (is_null($this->pricingTickInfo)) {
106 4
            $this->pricingTickInfo = new PricingTickInfo();
107 4
        }
108 4
        if (is_null($this->pricingTickInfo->pricingTicketing)) {
109 4
            $this->pricingTickInfo->pricingTicketing = new PricingTicketing();
110 4
        }
111
112 4
        $this->pricingTickInfo->pricingTicketing->priceType[] = $type;
113 4
    }
114
}
115