Completed
Push — master ( dcb951...0b0e41 )
by Dieter
07:13
created

PenDisInformation   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 82
rs 10
c 2
b 1
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 3
A loadObFees() 0 18 4
A loadPaxDiscounts() 0 6 2
A makeObFeeFunction() 0 4 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\PricePnr13;
24
25
use Amadeus\Client\RequestOptions\Fare\PricePnr\ObFee;
26
27
/**
28
 * PenDisInformation
29
 *
30
 * @package Amadeus\Client\Struct\Fare\PricePnr13
31
 * @author Dieter Devlieghere <[email protected]>
32
 */
33
class PenDisInformation
34
{
35
    const QUAL_PENALTY = 700;
36
    const QUAL_DISCOUNT = 701;
37
    const QUAL_OB_FEES = "OBF";
38
    const QUAL_ZAPOFF_DISCOUNT = "ZAP";
39
40
    /**
41
     * self::QUAL_*
42
     *
43
     * @var string
44
     */
45
    public $discountPenaltyQualifier;
46
47
    /**
48
     * @var DiscountPenaltyDetails[]
49
     */
50
    public $discountPenaltyDetails = [];
51
52
    /**
53
     * PenDisInformation constructor.
54
     *
55
     * @param string|null $discountPenaltyQualifier
56
     * @param mixed $data
57
     */
58
    public function __construct($discountPenaltyQualifier = null, $data)
59
    {
60
        $this->discountPenaltyQualifier = $discountPenaltyQualifier;
61
62
        switch ($discountPenaltyQualifier) {
63
            case PenDisInformation::QUAL_OB_FEES:
64
                $this->loadObFees($data);
65
                break;
66
            case PenDisInformation::QUAL_DISCOUNT:
67
                $this->loadPaxDiscounts($data);
68
                break;
69
        }
70
    }
71
72
    /**
73
     * @param ObFee[] $obFees
74
     */
75
    protected function loadObFees($obFees)
76
    {
77
        foreach ($obFees as $obFee) {
78
            $amountType = (!empty($obFee->amount)) ?
79
                DiscountPenaltyDetails::AMOUNTTYPE_FIXED_WHOLE_AMOUNT :
80
                DiscountPenaltyDetails::AMOUNTTYPE_PERCENTAGE;
81
82
            $rate = (!empty($obFee->amount)) ? $obFee->amount : $obFee->percentage;
83
84
            $this->discountPenaltyDetails[] = new DiscountPenaltyDetails(
85
                $obFee->rate,
86
                self::makeObFeeFunction($obFee->include),
87
                $amountType,
88
                $rate,
89
                $obFee->currency
90
            );
91
        }
92
    }
93
94
    /**
95
     * @param string[] $discounts
96
     */
97
    protected function loadPaxDiscounts($discounts)
98
    {
99
        foreach ($discounts as $discount) {
100
            $this->discountPenaltyDetails[] = new DiscountPenaltyDetails($discount);
101
        }
102
    }
103
104
    /**
105
     * Make the correct function code
106
     *
107
     * @param bool $include
108
     * @return string
109
     */
110
    protected static function makeObFeeFunction($include)
111
    {
112
        return ($include === true) ? ObFee::FUNCTION_INCLUDE : ObFee::FUNCTION_EXCLUDE;
113
    }
114
}
115