Completed
Push — master ( 8f168b...4b1795 )
by Dieter
09:49
created

BasePricingMessage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 44
ccs 15
cts 15
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hasPricingGroup() 0 12 3
A mergeOptions() 0 11 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;
24
25
use Amadeus\Client\Struct\BaseWsMessage;
26
use Amadeus\Client\Struct\Fare\PricePnr13\PricingOptionGroup;
27
use Amadeus\Client\Struct\Service\IntegratedPricing\PricingOption as ServicePriceOpt;
28
29
/**
30
 * BasePricingMessage
31
 *
32
 * Provides some basic functionality for all pricing messages which work with 'pricingOptionGroup's
33
 *
34
 * @package Amadeus\Client\Struct\Fare
35
 * @author Dieter Devlieghere <[email protected]>
36
 */
37
class BasePricingMessage extends BaseWsMessage
38
{
39
    /**
40
     * Avoid double pricing groups when combining an explicitly provided override option with a specific parameter
41
     * that uses the same override option.
42
     *
43
     * Backwards compatibility with PricePnrWithBookingClass12
44
     *
45
     * @param string $optionKey
46
     * @param PricingOptionGroup[]|ServicePriceOpt[] $priceOptions
47
     * @return bool
48
     */
49 8
    protected static function hasPricingGroup($optionKey, $priceOptions)
50
    {
51 8
        $found = false;
52
53 8
        foreach ($priceOptions as $pog) {
54 7
            if ($pog->pricingOptionKey->pricingOptionKey === $optionKey) {
55 2
                $found = true;
56 2
            }
57 8
        }
58
59 8
        return $found;
60
    }
61
62
    /**
63
     * Merges Pricing options
64
     *
65
     * @param PricingOptionGroup[]|ServicePriceOpt[] $existingOptions
66
     * @param PricingOptionGroup[]|ServicePriceOpt[] $newOptions
67
     * @return PricingOptionGroup[]|ServicePriceOpt[] merged array
68
     */
69 39
    protected static function mergeOptions($existingOptions, $newOptions)
70
    {
71 39
        if (!empty($newOptions)) {
72 32
            $existingOptions = array_merge(
73 32
                $existingOptions,
74
                $newOptions
75 32
            );
76 32
        }
77
78 39
        return $existingOptions;
79
    }
80
}
81