Test Failed
Push — master ( 8b9323...80aa1a )
by Dieter
13:04
created

StandaloneCatalogue::loadFlightDetails()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
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
namespace Amadeus\Client\Struct\Service;
23
24
use Amadeus\Client\RequestOptions\Fare\InformativePricing\Passenger;
25
use Amadeus\Client\RequestOptions\Fare\InformativePricing\PricingOptions;
26
use Amadeus\Client\RequestOptions\Fare\InformativePricing\Segment;
27
use Amadeus\Client\RequestOptions\ServiceStandaloneCatalogueOptions;
28
use Amadeus\Client\Struct\BaseWsMessage;
29
use Amadeus\Client\Struct\Service\StandaloneCatalogue\PassengerInfoGroup;
30
use Amadeus\Client\Struct\Service\StandaloneCatalogue\FlightInfo;
31
use Amadeus\Client\Struct\Fare\PricePNRWithBookingClass13;
32
33
/**
34
 * StandaloneCatalogue
35
 *
36
 * @package Amadeus\Client\Struct\Fare
37
 * @author Arvind Pandey <[email protected]>
38
 */
39
class StandaloneCatalogue extends BaseWsMessage
40
{
41
42
    /**
43
     *
44
     * @var PassengerInfoGroup[]
45
     */
46
    public $passengerInfoGroup = [];
47
48
    /**
49
     *
50
     * @var FlightInfo[]
51
     */
52
    public $flightInfo = [];
53
54
    /**
55
     *
56
     * @var PricingOptions[]
57
     */
58
    public $pricingOption = [];
59
60
    /**
61
     * StandaloneCatalogue constructor.
62
     *
63
     * @param ServiceStandaloneCatalogueOptions|null $options
64
     */
65 View Code Duplication
    public function __construct($options)
0 ignored issues
show
Duplication introduced by
This method 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...
66
    {
67
        if (! is_null($options)) {
68
            $this->loadPassengers($options->passengers);
69
            
70
            $this->loadFlightDetails($options->segments);
71
            
72
            $this->loadPricingOptions($options->pricingOptions);
73
        }
74
    }
75
76
    /**
77
     *
78
     * @param Passenger[] $passengers
79
     */
80
    protected function loadPassengers($passengers)
81
    {
82
        $counter = 1;
83
        foreach ($passengers as $passenger) {
84
            $this->passengerInfoGroup[] = new PassengerInfoGroup($passenger, $counter);
85
            $counter ++;
86
        }
87
    }
88
89
    /**
90
     *
91
     * @param Segment[] $segments
92
     */
93
    protected function loadFlightDetails($segments)
94
    {
95
        foreach ($segments as $segment) {
96
            $this->flightInfo[] = new FlightInfo($segment);
97
        }
98
    }
99
100
    /**
101
     *
102
     * @param PricingOptions|null $pricingOptions
103
     */
104
    protected function loadPricingOptions($pricingOptions)
105
    {
106
        $this->pricingOption = PricePNRWithBookingClass13::loadPricingOptionsFromRequestOptions($pricingOptions);
0 ignored issues
show
Bug introduced by
It seems like $pricingOptions defined by parameter $pricingOptions on line 104 can be null; however, Amadeus\Client\Struct\Fa...onsFromRequestOptions() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
Documentation Bug introduced by
It seems like \Amadeus\Client\Struct\F...ptions($pricingOptions) of type array<integer,object<Ama...13\PricingOptionGroup>> is incompatible with the declared type array<integer,object<Ama...ricing\PricingOptions>> of property $pricingOption.

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...
107
    }
108
}
109