Completed
Push — develop ( a8951f...6805ee )
by Dieter
05:48
created

AvailabilityDetails::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 4
nop 2
1
<?php
2
/**
3
 * Amadeus
4
 *
5
 * Copyright 2015 Amadeus Benelux NV
6
 */
7
8
namespace Amadeus\Client\Struct\Air\MultiAvailability;
9
10
/**
11
 * AvailabilityDetails
12
 *
13
 * @package Amadeus\Client\Struct\Air\MultiAvailability
14
 * @author Dieter Devlieghere <[email protected]>
15
 */
16
class AvailabilityDetails
17
{
18
    /**
19
     * @var string
20
     */
21
    public $departureDate;
22
23
    /**
24
     * @var string
25
     */
26
    public $departureTime;
27
28
    /**
29
     * @var string
30
     */
31
    public $arrivalDate;
32
33
    /**
34
     * @var string
35
     */
36
    public $arrivalTime;
37
38
    /**
39
     * AvailabilityDetails constructor.
40
     *
41
     * @param \DateTime $departureDate
42
     * @param \DateTime|null $arrivalDate
43
     */
44
    public function __construct($departureDate, $arrivalDate = null)
45
    {
46
        if ($departureDate instanceof \DateTime) {
47
            $depArr = $this->loadDateInfo($departureDate);
48
            $this->departureDate = $depArr['date'];
49
            $this->departureTime = $depArr['time'];
50
        }
51
52
        if ($arrivalDate instanceof \DateTime) {
53
            $arrArr = $this->loadDateInfo($arrivalDate);
54
            $this->arrivalDate = $arrArr['date'];
55
            $this->arrivalTime = $arrArr['time'];
56
        }
57
    }
58
59
    /**
60
     * @param \DateTime $date
61
     * @return array ['date' => '200316', 'time'=>'1415']
62
     */
63
    protected function loadDateInfo(\DateTime $date)
64
    {
65
        $dateInfo = [
66
            'date' => null,
67
            'time' => null
68
        ];
69
70
        $dateInfo['date'] = $date->format('dmy');
71
72
        $time = $date->format('Hi');
73
        if ($time !== '0000') {
74
            $dateInfo['time'] = $time;
75
        }
76
77
        return $dateInfo;
78
    }
79
}
80