Completed
Push — master ( a82346...60b026 )
by Dieter
09:40
created

FlightDate::loadArrivalDate()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 12
cts 12
cp 1
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 9
nc 5
nop 2
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
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|int
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
        $this->loadDepartureDate($departureDate);
73
74 92
        $this->loadArrivalDate($arrivalDate, $arrivalTime);
75
76 92
        if (!is_null($dateVariation)) {
77 16
            $this->dateVariation = $dateVariation;
78 8
        }
79 92
    }
80
81
    /**
82
     * @param \DateTime|string|null $departureDate
83
     */
84 92
    protected function loadDepartureDate($departureDate)
85
    {
86 92
        if ($departureDate instanceof \DateTime) {
87 80
            $this->departureDate = ($departureDate->format('dmy') !== '000000') ? $departureDate->format('dmy') : null;
88 80
            $time = $departureDate->format('Hi');
89 80
            if ($time !== '0000') {
90 68
                $this->departureTime = $time;
91 28
            }
92 52
        } elseif (!empty($departureDate)) {
93 12
            $this->departureDate = $departureDate;
94 6
        }
95 92
    }
96
97
    /**
98
     * @param \DateTime|null $arrivalDate
99
     * @param string|\DateTime|null $arrivalTime
100
     */
101 92
    protected function loadArrivalDate($arrivalDate, $arrivalTime)
102
    {
103 92
        if ($arrivalDate instanceof \DateTime) {
104 24
            $this->setArrivalDate($arrivalDate);
105 84
        } elseif ($arrivalTime instanceof \DateTime) {
106 8
            $time = $arrivalTime->format('Hi');
107 8
            if ($time !== '0000') {
108 8
                $this->arrivalTime = $time;
109 4
            }
110 72
        } elseif (is_string($arrivalTime) && !empty($arrivalTime)) {
111 4
            $this->arrivalTime = $arrivalTime;
112 2
        }
113 92
    }
114
115
    /**
116
     * Load Arrival date info from \DateTime
117
     *
118
     * @param \DateTime $arrivalDate
119
     */
120 32
    public function setArrivalDate(\DateTime $arrivalDate)
121
    {
122 32
        $this->arrivalDate = ($arrivalDate->format('dmy') !== '000000') ? $arrivalDate->format('dmy') : null;
123 32
        $time = $arrivalDate->format('Hi');
124 32
        if ($time !== '0000') {
125 32
            $this->arrivalTime = $time;
126 16
        }
127 32
    }
128
}
129