Completed
Push — feature/link_expense_note ( dad966...3db735 )
by Laurent
02:03
created

QuarterPilotMissionCollection::hasMission()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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