Completed
Push — master ( 5594ea...e43a77 )
by Laurent
03:34 queued 01:39
created

PilotMissions::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 */
5
6
use Webmozart\Assert\Assert;
7
8
/**
9
 * PilotMissions class
10
 *
11
 * @author Laurent De Coninck <[email protected]>
12
 */
13
class PilotMissions
14
{
15
16
    /**
17
     * @var int
18
     */
19
    private $pilotId;
20
21
    /**
22
     * @var string
23
     */
24
    private $pilotFirstname;
25
26
    /**
27
     * @var string
28
     */
29
    private $pilotLastname;
30
31
    /**
32
     * @var array|QuarterMission[]
33
     */
34
    private $quarterMissions;
35
36
    /**
37
     * @param int    $pilotId
38
     * @param string $pilotFirstname
39
     * @param string $pilotLastname
40
     */
41
    public function __construct($pilotId, $pilotFirstname, $pilotLastname)
42
    {
43
        Assert::integerish($pilotId);
44
        Assert::greaterThan($pilotId, 0);
45
46
        Assert::nullOrString($pilotLastname);
47
        Assert::nullOrString($pilotFirstname);
48
49
        $this->pilotId = (int)$pilotId;
50
        $this->pilotFirstname = $pilotFirstname;
51
        $this->pilotLastname = $pilotLastname;
52
53
        $this->quarterMissions = [];
54
    }
55
56
57
    /**
58
     * @param int $quarter
59
     * @param int $numberOfFlights
60
     * @param int $numberOfKilometers
61
     */
62
    public function addQuarter($quarter, $numberOfFlights, $numberOfKilometers){
63
        Assert::integerish($quarter);
64
        $quarter = (int)$quarter;
65
66
        Assert::keyNotExists($this->quarterMissions, $quarter);
67
68
        $this->quarterMissions[$quarter] = new QuarterMission($quarter, $numberOfFlights, $numberOfKilometers);
69
    }
70
71
    /**
72
     * @return int
73
     */
74
    public function getPilotId()
75
    {
76
        return $this->pilotId;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function getPilotFirstname()
83
    {
84
        return $this->pilotFirstname;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getPilotLastname()
91
    {
92
        return $this->pilotLastname;
93
    }
94
95
    /**
96
     * @param int $quarter
97
     *
98
     * @return int
99
     */
100
    public function getTotalOfKilometersForQuarter($quarter)
101
    {
102
        return $this->getQuarterMission($quarter)->getNumberOfKilometers();
103
    }
104
105
    /**
106
     * @param int $quarter
107
     *
108
     * @return int
109
     */
110
    public function getNumberOfFlightsForQuarter($quarter)
111
    {
112
        return $this->getQuarterMission($quarter)->getNumberOfFlights();
113
    }
114
115
    /**
116
     * Get the QuarterMission for a given quarter.
117
     *
118
     * @param int $quarter
119
     *
120
     * @return QuarterMission
121
     */
122
    private function getQuarterMission($quarter){
123
        Assert::integer($quarter);
124
        Assert::greaterThan($quarter, 0);
125
        Assert::lessThanEq($quarter, 4);
126
127
        if(!isset($this->quarterMissions[$quarter])){
128
            return new QuarterMission($quarter,0,0);
129
        }
130
131
        return $this->quarterMissions[$quarter];
132
    }
133
134
    /**
135
     * @return string
136
     */
137
    public function getPilotName()
138
    {
139
        return $this->pilotFirstname.' '.$this->pilotLastname;
140
    }
141
}