Total Complexity | 9 |
Total Lines | 73 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
11 | trait MoneyFunctions |
||
12 | { |
||
13 | /** |
||
14 | * @param Money $first |
||
15 | * @param Money ...$collection |
||
16 | * |
||
17 | * @return Money |
||
18 | */ |
||
19 | 3 | public static function min(Money $first, Money ...$collection): Money |
|
20 | { |
||
21 | 3 | $min = $first; |
|
22 | |||
23 | 3 | foreach ($collection as $money) { |
|
24 | 2 | if ($money->lessThan($min)) { |
|
25 | 2 | $min = $money; |
|
26 | } |
||
27 | } |
||
28 | |||
29 | 3 | return $min; |
|
30 | } |
||
31 | |||
32 | /** |
||
33 | * Checks whether the value represented by this object is less than the other. |
||
34 | * |
||
35 | * @param Money $other |
||
36 | * |
||
37 | * @return bool |
||
38 | */ |
||
39 | 5 | public function lessThan(Money $other): bool |
|
40 | { |
||
41 | 5 | return $this->compare($other) === -1; |
|
|
|||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @param Money $first |
||
46 | * @param Money ...$collection |
||
47 | * |
||
48 | * @return Money |
||
49 | */ |
||
50 | 3 | public static function max(Money $first, Money ...$collection): Money |
|
51 | { |
||
52 | 3 | $max = $first; |
|
53 | |||
54 | 3 | foreach ($collection as $money) { |
|
55 | 2 | if ($money->greaterThan($max)) { |
|
56 | 2 | $max = $money; |
|
57 | } |
||
58 | } |
||
59 | |||
60 | 3 | return $max; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * Checks whether the value represented by this object is greater than the other. |
||
65 | * |
||
66 | * @param Money $other |
||
67 | * |
||
68 | * @return bool |
||
69 | */ |
||
70 | 5 | public function greaterThan(Money $other): bool |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * @param Money $first |
||
77 | * @param Money ...$collection |
||
78 | * |
||
79 | * @return Money |
||
80 | */ |
||
81 | 6 | public static function sum(Money $first, Money ...$collection): Money |
|
84 | } |
||
85 | |||
88 | } |