Test Failed
Pull Request — master (#344)
by Andrew
09:56
created

PenDisInformation::loadZapOffDiscounts()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 11
cp 0
rs 9.7333
c 0
b 0
f 0
cc 4
nc 5
nop 1
crap 20
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\PricePnr13;
24
25
use Amadeus\Client\RequestOptions\Fare\PricePnr\ObFee;
26
use Amadeus\Client\RequestOptions\Fare\PricePnr\ZapOff;
27
28
/**
29
 * PenDisInformation
30
 *
31
 * @package Amadeus\Client\Struct\Fare\PricePnr13
32
 * @author Dieter Devlieghere <[email protected]>
33
 */
34
class PenDisInformation
35
{
36
    const QUAL_PENALTY = 700;
37
    const QUAL_DISCOUNT = 701;
38
    const QUAL_OB_FEES = "OBF";
39
    const QUAL_ZAPOFF_DISCOUNT = "ZAP";
40
41
    /**
42
     * self::QUAL_*
43
     *
44
     * @var string
45
     */
46
    public $discountPenaltyQualifier;
47
48
    /**
49
     * @var DiscountPenaltyDetails[]
50
     */
51
    public $discountPenaltyDetails = [];
52
53
    /**
54
     * PenDisInformation constructor.
55
     *
56
     * @param string|null $discountPenaltyQualifier
57
     * @param mixed $data
58
     */
59 18
    public function __construct($discountPenaltyQualifier, $data)
60
    {
61 18
        $this->discountPenaltyQualifier = $discountPenaltyQualifier;
62
63 12
        switch ($discountPenaltyQualifier) {
64 6
            case PenDisInformation::QUAL_OB_FEES:
65 3
                $this->loadObFees($data);
66 3
                break;
67 5
            case PenDisInformation::QUAL_DISCOUNT:
68 15
                $this->loadPaxDiscounts($data);
69 15
                break;
70
            case PenDisInformation::QUAL_ZAPOFF_DISCOUNT:
71
                $this->loadZapOffDiscounts($data);
72
                break;
73
        }
74 18
    }
75
76
    /**
77
     * @param ObFee[] $obFees
78
     */
79 3
    protected function loadObFees($obFees)
80
    {
81 3
        foreach ($obFees as $obFee) {
82 3
            $amountType = (!empty($obFee->amount)) ?
83 3
                DiscountPenaltyDetails::AMOUNTTYPE_FIXED_WHOLE_AMOUNT : DiscountPenaltyDetails::AMOUNTTYPE_PERCENTAGE;
84
85 3
            $rate = (!empty($obFee->amount)) ? $obFee->amount : $obFee->percentage;
86
87 3
            $this->discountPenaltyDetails[] = new DiscountPenaltyDetails(
88 3
                $obFee->rate,
89 3
                self::makeObFeeFunction($obFee->include),
90 2
                $amountType,
91 2
                $rate,
92 3
                $obFee->currency
93
            );
94
        }
95 3
    }
96
97
    /**
98
     * @param string[] $discounts
99
     */
100 15
    protected function loadPaxDiscounts($discounts)
101
    {
102 15
        foreach ($discounts as $discount) {
103 15
            $this->discountPenaltyDetails[] = new DiscountPenaltyDetails($discount);
104
        }
105 15
    }
106
107
    /**
108
     * @param $zapOffs ZapOff[]
109
     */
110
    protected function loadZapOffDiscounts($zapOffs)
111
    {
112
        foreach ($zapOffs as $zapOff) {
113
            $amountType = (isset($zapOff->amount)) ?
114
                DiscountPenaltyDetails::AMOUNTTYPE_FIXED_WHOLE_AMOUNT : DiscountPenaltyDetails::AMOUNTTYPE_PERCENTAGE;
115
116
            $rate = (isset($zapOff->amount)) ? $zapOff->amount : $zapOff->percentage;
117
118
            $this->discountPenaltyDetails[] = new DiscountPenaltyDetails(
119
                $zapOff->rate,
120
                $zapOff->applyTo,
121
                $amountType,
122
                $rate
123
            );
124
        }
125
    }
126
127
    /**
128
     * Make the correct function code
129
     *
130
     * @param bool $include
131
     * @return string
132
     */
133 3
    protected static function makeObFeeFunction($include)
134
    {
135 3
        return ($include === true) ? ObFee::FUNCTION_INCLUDE : ObFee::FUNCTION_EXCLUDE;
136
    }
137
}
138