Completed
Push — develop ( 79a83d...d8326f )
by Dieter
05:21
created

SegmentGroup::loadAdditionalSegmentDetails()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 3
eloc 3
nc 2
nop 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\InformativePricing13;
24
25
use Amadeus\Client\RequestOptions\Fare\InformativePricing\Segment;
26
use Amadeus\Client\Struct\Air\FlightTypeDetails;
27
28
/**
29
 * SegmentGroup
30
 *
31
 * @package Amadeus\Client\Struct\Fare\InformativePricing13
32
 * @author Dieter Devlieghere <[email protected]>
33
 */
34
class SegmentGroup
35
{
36
    /**
37
     * @var SegmentInformation
38
     */
39
    public $segmentInformation;
40
41
    /**
42
     * @var AdditionalSegmentDetails
43
     */
44
    public $additionnalSegmentDetails;
45
46
    /**
47
     * @var Inventory
48
     */
49
    public $inventory;
50
51
    /**
52
     * SegmentGroup constructor.
53
     *
54
     * @param Segment $options
55
     */
56
    public function __construct($options)
57
    {
58
        $this->segmentInformation = new SegmentInformation(
59
            $options->segmentTattoo,
60
            $options->departureDate,
61
            $options->from,
62
            $options->to,
63
            $options->marketingCompany,
64
            $options->flightNumber,
65
            $options->bookingClass
66
        );
67
68
        $this->loadOptionalSegmentInformation($options);
69
70
        $this->loadInventory($options->inventory);
71
    }
72
73
    /**
74
     * Load non-required options if available
75
     *
76
     * @param Segment $options
77
     */
78
    protected function loadOptionalSegmentInformation($options)
79
    {
80
        if (!empty($options->operatingCompany)) {
81
            $this->segmentInformation->companyDetails->operatingCompany = $options->operatingCompany;
82
        }
83
84
        if ($options->arrivalDate instanceof \DateTime) {
85
            $this->segmentInformation->flightDate->setArrivalDate($options->arrivalDate);
86
        }
87
88
        if (!empty($options->groupNumber)) {
89
            $this->segmentInformation->flightTypeDetails = new FlightTypeDetails($options->groupNumber);
90
        }
91
92
        $this->loadAdditionalSegmentDetails($options->airplaneCode, $options->nrOfStops);
93
    }
94
95
    /**
96
     * @param string|null $airplaneCode
97
     * @param int|null $nrOfStops
98
     */
99
    protected function loadAdditionalSegmentDetails($airplaneCode, $nrOfStops)
100
    {
101
        if (!empty($airplaneCode) || !empty($nrOfStops)) {
102
            $this->additionnalSegmentDetails = new AdditionalSegmentDetails($airplaneCode, $nrOfStops);
103
        }
104
    }
105
106
    /**
107
     * Load inventory information
108
     *
109
     * @param array $inventory
110
     */
111
    protected function loadInventory($inventory)
112
    {
113
        if (is_array($inventory) && count($inventory) > 0) {
114
            $this->inventory = new Inventory();
115
116
            foreach ($inventory as $bookingClass => $availabilityAmount) {
117
                $this->inventory->bookingClassDetails[] = new BookingClassDetails(
118
                    $bookingClass,
119
                    $availabilityAmount
120
                );
121
            }
122
        }
123
    }
124
}
125