Completed
Pull Request — master (#220)
by
unknown
22:15 queued 10:53
created

FlightInfo::loadOptionalSegmentInformation()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 16
loc 16
ccs 0
cts 13
cp 0
rs 9.7333
c 0
b 0
f 0
cc 4
nc 8
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\Service\StandaloneCatalogue;
24
25
use Amadeus\Client\RequestOptions\Fare\InformativePricing\Segment;
26
use Amadeus\Client\Struct\Fare\InformativePricing13\SegmentInformation;
27
use Amadeus\Client\Struct\Air\FlightTypeDetails;
28
29
/**
30
 * FlightInfo
31
 *
32
 * @package Amadeus\Client\Struct\Service\StandaloneCatalogue
33
 * @author Arvind Pandey <[email protected]>
34
 */
35 View Code Duplication
class FlightInfo
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
{
37
    /**
38
     * @var flightDetails
39
     */
40
    public $flightDetails;
41
42
    /**
43
     * @var AdditionalSegmentDetails
44
     */
45
    public $additionnalSegmentDetails;
46
47
    /**
48
     * @var Inventory
49
     */
50
    public $inventory;
51
52
    /**
53
     * SegmentGroup constructor.
54
     *
55
     * @param Segment $options
56
     */
57
    public function __construct($options)
58
    {
59
        $this->flightDetails = new SegmentInformation(
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Amadeus\Client\Stru...$options->bookingClass) of type object<Amadeus\Client\St...g13\SegmentInformation> is incompatible with the declared type object<Amadeus\Client\St...atalogue\flightDetails> of property $flightDetails.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
60
            $options->segmentTattoo,
61
            $options->departureDate,
62
            $options->from,
63
            $options->to,
64
            $options->marketingCompany,
65
            $options->flightNumber,
66
            $options->bookingClass
67
        );
68
69
        $this->loadOptionalSegmentInformation($options);
70
71
        $this->loadInventory($options->inventory);
72
    }
73
74
    /**
75
     * Load non-required options if available
76
     *
77
     * @param Segment $options
78
     */
79
    protected function loadOptionalSegmentInformation($options)
80
    {
81
        if (!empty($options->operatingCompany)) {
82
            $this->flightDetails->companyDetails->operatingCompany = $options->operatingCompany;
83
        }
84
85
        if ($options->arrivalDate instanceof \DateTime) {
86
            $this->flightDetails->flightDate->setArrivalDate($options->arrivalDate);
87
        }
88
89
        if (!empty($options->groupNumber)) {
90
            $this->flightDetails->flightTypeDetails = new FlightTypeDetails($options->groupNumber);
91
        }
92
93
        $this->loadAdditionalSegmentDetails($options->airplaneCode, $options->nrOfStops);
94
    }
95
96
    /**
97
     * @param string|null $airplaneCode
98
     * @param int|null $nrOfStops
99
     */
100
    protected function loadAdditionalSegmentDetails($airplaneCode, $nrOfStops)
101
    {
102
        if (!empty($airplaneCode) || !empty($nrOfStops)) {
103
            $this->additionalFlightInfo = new AdditionalSegmentDetails($airplaneCode, $nrOfStops);
0 ignored issues
show
Bug introduced by
The property additionalFlightInfo does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
104
        }
105
    }
106
107
    /**
108
     * Load inventory information
109
     *
110
     * @param array $inventory
111
     */
112
    protected function loadInventory($inventory)
113
    {
114
        if (is_array($inventory) && count($inventory) > 0) {
115
            $this->inventory = new Inventory();
116
117
            foreach ($inventory as $bookingClass => $availabilityAmount) {
118
                $this->inventory->bookingClassDetails[] = new BookingClassDetails(
119
                    $bookingClass,
120
                    $availabilityAmount
121
                );
122
            }
123
        }
124
    }
125
}
126