Test Failed
Pull Request — master (#220)
by
unknown
08:55
created

FlightInfo   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 91
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 2
cbo 5
dl 91
loc 91
ccs 0
cts 45
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 16 16 1
A loadOptionalSegmentInformation() 16 16 4
A loadAdditionalSegmentDetails() 6 6 3
A loadInventory() 13 13 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Service\StandaloneCatalogue\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 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...
35
{
36
    /**
37
     * @var SegmentInformation
38
     */
39
    public $flightDetails;
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->flightDetails = 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);
0 ignored issues
show
Bug introduced by
The property inventory does not seem to exist in Amadeus\Client\RequestOp...daloneCatalogue\Segment.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
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->flightDetails->companyDetails->operatingCompany = $options->operatingCompany;
82
        }
83
84
        if ($options->arrivalDate instanceof \DateTime) {
85
            $this->flightDetails->flightDate->setArrivalDate($options->arrivalDate);
86
        }
87
88
        if (!empty($options->groupNumber)) {
89
            $this->flightDetails->flightTypeDetails = new FlightTypeDetails($options->groupNumber);
0 ignored issues
show
Bug introduced by
The property groupNumber does not seem to exist in Amadeus\Client\RequestOp...daloneCatalogue\Segment.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
90
        }
91
92
        $this->loadAdditionalSegmentDetails($options->airplaneCode, $options->nrOfStops);
0 ignored issues
show
Bug introduced by
The property airplaneCode does not seem to exist in Amadeus\Client\RequestOp...daloneCatalogue\Segment.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
The property nrOfStops does not seem to exist in Amadeus\Client\RequestOp...daloneCatalogue\Segment.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
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->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...
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