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

FlightInfo   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 62.75 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 32
loc 51
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 16 16 1
A loadOptionalSegmentInformation() 16 16 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\Fare\InformativePricing\Segment;
26
use Amadeus\Client\Struct\Fare\InformativePricing13\SegmentGroup;
27
use Amadeus\Client\Struct\Fare\InformativePricing13\SegmentInformation;
28
use Amadeus\Client\Struct\Air\FlightTypeDetails;
29
30
/**
31
 * FlightInfo
32
 *
33
 * @package Amadeus\Client\Struct\Service\StandaloneCatalogue
34
 * @author Arvind Pandey <[email protected]>
35
 */
36
class FlightInfo extends SegmentGroup
37
{
38
    /**
39
     * @var SegmentInformation
40
     */
41
    public $flightDetails;
42
43
    /**
44
     * FlightInfo constructor.
45
     *
46
     * @param Segment $options
47
     */
48 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...
49
    {
50
        $this->flightDetails = new SegmentInformation(
51
            $options->segmentTattoo,
52
            $options->departureDate,
53
            $options->from,
54
            $options->to,
55
            $options->marketingCompany,
56
            $options->flightNumber,
57
            $options->bookingClass
58
        );
59
60
        $this->loadOptionalSegmentInformation($options);
0 ignored issues
show
Documentation introduced by
$options is of type object<Amadeus\Client\Re...rmativePricing\Segment>, but the function expects a object<Amadeus\Client\St...neCatalogue\FlightInfo>.

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...
61
62
        SegmentGroup::loadInventory($options->inventory);
63
    }
64
65
    /**
66
     * Load non-required options if available
67
     *
68
     * @param FlightInfo $options
69
     */
70 View Code Duplication
    protected function loadOptionalSegmentInformation($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...
71
    {
72
        if (! empty($options->operatingCompany)) {
73
            $this->flightDetails->companyDetails->operatingCompany = $options->operatingCompany;
0 ignored issues
show
Bug introduced by
The property operatingCompany 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...
74
        }
75
        
76
        if ($options->arrivalDate instanceof \DateTime) {
77
            $this->flightDetails->flightDate->setArrivalDate($options->arrivalDate);
0 ignored issues
show
Bug introduced by
The property arrivalDate 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...
78
        }
79
        
80
        if (! empty($options->groupNumber)) {
81
            $this->flightDetails->flightTypeDetails = new FlightTypeDetails($options->groupNumber);
0 ignored issues
show
Bug introduced by
The property groupNumber 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...
82
        }
83
        
84
        SegmentGroup::loadAdditionalSegmentDetails($options->airplaneCode, $options->nrOfStops);
0 ignored issues
show
Bug introduced by
The property airplaneCode 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...
Bug introduced by
The property nrOfStops 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...
85
    }
86
}
87