Completed
Push — master ( 5242c7...dcb951 )
by Dieter
07:52
created

Create::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
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\Offer;
24
25
use Amadeus\Client\RequestOptions\Offer\AirRecommendation;
26
use Amadeus\Client\RequestOptions\OfferCreateOptions;
27
use Amadeus\Client\RequestOptions\Offer\ProductReference as ProdRefOpt;
28
use Amadeus\Client\Struct\BaseWsMessage;
29
use Amadeus\Client\Struct\Offer\Create\AirPricingRecommendation;
30
use Amadeus\Client\Struct\Offer\Create\ProductReference;
31
use Amadeus\Client\Struct\Offer\Create\TotalPrice;
32
33
/**
34
 * Offer_CreateOffer request structure
35
 *
36
 * @package Amadeus\Client\Struct\Offer
37
 * @author Dieter Devlieghere <[email protected]>
38
 */
39
class Create extends BaseWsMessage
40
{
41
    /**
42
     * @var Create\AirPricingRecommendation[]
43
     */
44
    public $airPricingRecommendation = [];
45
46
    /**
47
     * @var Create\TotalPrice
48
     */
49
    public $totalPrice;
50
51
    /**
52
     * @var Create\ProductReference
53
     */
54
    public $productReference;
55
56
    /**
57
     * Offer_CreateOffer constructor.
58
     *
59
     * @param OfferCreateOptions $options
60
     */
61
    public function __construct(OfferCreateOptions $options)
62
    {
63
        if (!empty($options->airRecommendations)) {
64
            $this->loadAirRecommendations($options->airRecommendations);
65
        } else {
66
            $this->loadProdRef($options->productReferences);
67
        }
68
69
        $this->loadMarkup($options->markupAmount, $options->markupCurrency);
70
    }
71
72
    /**
73
     * @param AirRecommendation[] $airRecommendations
74
     */
75
    protected function loadAirRecommendations($airRecommendations)
76
    {
77
        foreach ($airRecommendations as $airRecommendation) {
78
            $this->airPricingRecommendation[] = new AirPricingRecommendation($airRecommendation);
79
        }
80
    }
81
82
    /**
83
     * @param ProdRefOpt[] $productReferences
84
     */
85
    protected function loadProdRef($productReferences)
86
    {
87
        $this->productReference = new ProductReference($productReferences);
88
    }
89
90
    /**
91
     * @param int|null $amount
92
     * @param string|null $currency
93
     */
94
    protected function loadMarkup($amount, $currency)
95
    {
96
        if (!is_null($amount) && !is_null($currency)) {
97
            $this->totalPrice = new TotalPrice($amount, $currency);
98
        }
99
    }
100
}
101