Completed
Pull Request — master (#5)
by Laurent
02:35 queued 42s
created

MonthlyFlightBill::getTotal()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 */
5
6
/**
7
 * @author Laurent De Coninck <[email protected]>
8
 */
9
class MonthlyFlightBill
10
{
11
12
    /**
13
     * @var Bbcvols[]|array
14
     */
15
    private $flights;
16
17
    /**
18
     * @var MoneyReceiver
19
     */
20
    private $moneyReceiver;
21
22
    /**
23
     * @param MoneyReceiver $moneyReceiver
24
     */
25
    public function __construct(MoneyReceiver $moneyReceiver)
26
    {
27
        $this->moneyReceiver = $moneyReceiver;
28
    }
29
30
    /**
31
     * @param Bbcvols $flight
32
     */
33
    public function addFlight(Bbcvols $flight)
34
    {
35
        $this->flights[] = $flight;
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function getReceiver()
42
    {
43
        return $this->moneyReceiver->getDisplayName();
44
    }
45
46
    /**
47
     * @return int
48
     */
49
    public function getFlightsCount()
50
    {
51
        return count($this->flights);
52
    }
53
54
    /**
55
     * @return int
56
     */
57
    public function getTotal()
58
    {
59
        $total = 0;
60
        foreach ($this->flights as $flight) {
61
            $total += $flight->cost;
62
        }
63
        return $total;
64
    }
65
66
    /**
67
     * @return float
68
     */
69
    public function getAverageByPax()
70
    {
71
        $total = $this->getTotal();
72
        $numberOfPax = $this->getNumberOfPassagers();
73
74
        return $total / $numberOfPax;
75
    }
76
77
    /**
78
     * @return int
79
     */
80
    private function getNumberOfPassagers()
81
    {
82
        $total = 0;
83
        foreach ($this->flights as $flight) {
84
            $total += $flight->nbrPax;
85
        }
86
        return $total;
87
    }
88
89
    /**
90
     * @return int
91
     */
92
    public function getReceiverId()
93
    {
94
        return $this->moneyReceiver->getId();
95
    }
96
97
    /**
98
     * @return array|Bbcvols[]
99
     */
100
    public function getFlights()
101
    {
102
        return $this->flights;
103
    }
104
105
106
}