Test Failed
Pull Request — master (#220)
by
unknown
11:06
created

StandaloneCatalogue::loadflightDetails()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 6
loc 6
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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\Struct\BaseWsMessage;
25
use Amadeus\Client\RequestOptions\Service\StandaloneCatalogue\Passenger;
26
use Amadeus\Client\RequestOptions\Fare\InformativePricing\Segment;
27
use Amadeus\Client\RequestOptions\ServiceStandaloneCatalogueOptions;
28
use Amadeus\Client\Struct\Service\StandaloneCatalogue\PassengerInfoGroup;
29
use Amadeus\Client\Struct\Service\StandaloneCatalogue\FlightInfo;
30
use Amadeus\Client\RequestOptions\Service\StandaloneCatalogue\PricingOptions;
31
32
/**
33
 * StandaloneCatalogue
34
 *
35
 * @package Amadeus\Client\Struct\Fare
36
 * @author StandaloneCatalogue.php
37
 */
38 View Code Duplication
class StandaloneCatalogue extends BaseWsMessage
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...
39
{
40
41
    /**
42
     *
43
     * @var passengerInfoGroup[]
44
     */
45
    public $passengerInfoGroup = [];
46
47
    /**
48
     *
49
     * @var flightInfo[]
50
     */
51
    public $flightInfo = [];
52
53
    /**
54
     *
55
     * @var pricingOption[]
56
     */
57
    public $pricingOption = [];
58
59
    /**
60
     * StandaloneCatalogue constructor.
61
     *
62
     * @param ServiceStandaloneCatalogueOptions|null $options
63
     */
64
    public function __construct($options)
65
    {
66
        if (! is_null($options)) {
67
            $this->loadPassengers($options->passengers);
68
            
69
            $this->loadflightDetails($options->segments);
70
            
71
            $this->loadPricingOptions($options->pricingOptions);
72
        }
73
    }
74
75
    /**
76
     *
77
     * @param Passenger[] $passengers
78
     */
79
    protected function loadPassengers($passengers)
80
    {
81
        $counter = 1;
82
        foreach ($passengers as $passenger) {
83
            $this->passengerInfoGroup[] = new PassengerInfoGroup($passenger, $counter);
0 ignored issues
show
Documentation introduced by
$passenger is of type object<Amadeus\Client\Re...oneCatalogue\Passenger>, but the function expects a object<Amadeus\Client\St...oneCatalogue\Passenger>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
84
            $counter ++;
85
        }
86
    }
87
88
    /**
89
     *
90
     * @param Segment[] $segments
91
     */
92
    protected function loadflightDetails($segments)
93
    {
94
        foreach ($segments as $segment) {
95
            $this->flightInfo[] = new flightInfo($segment);
96
        }
97
    }
98
99
    /**
100
     *
101
     * @param PricingOptions|null $pricingOptions
102
     */
103
    protected function loadPricingOptions($pricingOptions)
104
    {
105
        if (! ($pricingOptions instanceof PricingOptions)) {
106
            $pricingOptions = new PricingOptions();
107
        }
108
        $this->pricingOption = IntegratedPricing::loadPricingOptions($pricingOptions);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Amadeus\Client\Struct\S...ptions($pricingOptions) of type array<integer,object<Ama...Pricing\PricingOption>> is incompatible with the declared type array<integer,object<Ama...Service\pricingOption>> 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...
109
    }
110
}
111