Completed
Push — feature/select_customer_on_fli... ( c85fa6 )
by Laurent
02:07
created

QuarterPilotMissionCollection::addPilot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 3
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 */
5
6
/**
7
 * QuarterPilotMissionCollection class
8
 *
9
 * @author Laurent De Coninck <[email protected]>
10
 */
11
class QuarterPilotMissionCollection implements IteratorAggregate
12
{
13
14
    /**
15
     * @var array|QuarterMission[]
16
     */
17
    private $items;
18
19
    /**
20
     *
21
     */
22
    public function __construct()
23
    {
24
        $this->items = [];
25
    }
26
27
    /**
28
     * @param int $quarter
29
     * @param int $pilotId
30
     * @param string $pilotFirstname
31
     * @param string $pilotLastname
32
     * @param int $numberOfFlights
33
     * @param int $numberOfKilometers
34
     */
35
    public function addMission(
36
        $quarter,
37
        $pilotId,
38
        $pilotFirstname,
39
        $pilotLastname,
40
        $numberOfFlights,
41
        $numberOfKilometers
42
    )
43
    {
44
        $pilotId = (int)$pilotId;
45
46
        if (!isset($this->items[$pilotId])) {
47
            $this->items[$pilotId] = new PilotMissions($pilotId, $pilotFirstname, $pilotLastname);
48
        }
49
50
        $this->items[$pilotId]->addQuarter($quarter, $numberOfFlights, $numberOfKilometers);
51
    }
52
53
    /**
54
     * @param int $pilotId
55
     * @param string $pilotFirstname
56
     * @param string $pilotLastname
57
     */
58
    public function addPilot($pilotId, $pilotFirstname, $pilotLastname)
59
    {
60
        $pilotId = (int)$pilotId;
61
62
        if (isset($this->items[$pilotId])) {
63
            return;
64
        }
65
66
        $this->items[$pilotId] = new PilotMissions($pilotId, $pilotFirstname, $pilotLastname);
67
    }
68
69
70
    /**
71
     * @return ArrayIterator
72
     */
73
    public function getIterator()
74
    {
75
        return new ArrayIterator($this->items);
76
    }
77
78
    /**
79
     * @return boolean
80
     */
81
    public function hasMission()
82
    {
83
        return !empty($this->items);
84
    }
85
}