Passed
Push — master ( 227ab8...9a02f8 )
by Dieter
03:08
created

FlightDate::__construct()   C

Complexity

Conditions 11
Paths 60

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 11

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 24
cts 24
cp 1
rs 5.2653
c 0
b 0
f 0
cc 11
eloc 18
nc 60
nop 4
crap 11

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Air;
24
25
/**
26
 * FlightDate
27
 *
28
 * @package Amadeus\Client\Struct\Air
29
 * @author dieter <[email protected]>
30
 */
31
class FlightDate
32
{
33
    /**
34
     * DDMMYY
35
     *
36
     * @var string
37
     */
38
    public $departureDate;
39
    /**
40
     * HHMM
41
     *
42
     * @var string
43
     */
44
    public $departureTime;
45
    /**
46
     * DDMMYY
47
     *
48
     * @var string
49
     */
50
    public $arrivalDate;
51
    /**
52
     * HHMM
53
     *
54
     * @var string
55
     */
56
    public $arrivalTime;
57
    /**
58
     * @var string
59
     */
60
    public $dateVariation;
61
62
    /**
63
     * FlightDate constructor.
64
     *
65
     * @param string|\DateTime|null $departureDate in format DDMMYY or \DateTime
66
     * @param \DateTime|null $arrivalDate
67
     * @param string|\DateTime|null $arrivalTime
68
     * @param int|null $dateVariation
69
     */
70 92
    public function __construct($departureDate, $arrivalDate = null, $arrivalTime = null, $dateVariation = null)
71
    {
72 92
        if ($departureDate instanceof \DateTime) {
73 80
            $this->departureDate = ($departureDate->format('dmy') != '000000') ? $departureDate->format('dmy') : null;
74 80
            $time = $departureDate->format('Hi');
75 80
            if ($time !== "0000") {
76 68
                $this->departureTime = $time;
77 28
            }
78 52
        } elseif (!empty($departureDate)) {
79 12
            $this->departureDate = $departureDate;
80 6
        }
81
82 92
        if ($arrivalDate instanceof \DateTime) {
83 24
            $this->setArrivalDate($arrivalDate);
84 84
        } elseif ($arrivalTime instanceof \DateTime) {
85 8
            $time = $arrivalTime->format('Hi');
86 8
            if ($time !== "0000") {
87 8
                $this->arrivalTime = $time;
88 4
            }
89 72
        } elseif (is_string($arrivalTime) && !empty($arrivalTime)) {
90 4
            $this->arrivalTime = $arrivalTime;
91 2
        }
92
93 92
        if (!is_null($dateVariation)) {
94 16
            $this->dateVariation = $dateVariation;
0 ignored issues
show
Documentation Bug introduced by
The property $dateVariation was declared of type string, but $dateVariation is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
95 8
        }
96 92
    }
97
98
    /**
99
     * Load Arrival date info from \DateTime
100
     *
101
     * @param \DateTime $arrivalDate
102
     */
103 32
    public function setArrivalDate(\DateTime $arrivalDate)
104
    {
105 32
        $this->arrivalDate = ($arrivalDate->format('dmy') != '000000') ? $arrivalDate->format('dmy') : null;
106 32
        $time = $arrivalDate->format('Hi');
107 32
        if ($time !== "0000") {
108 32
            $this->arrivalTime = $time;
109 16
        }
110 32
    }
111
}
112