Total Complexity | 5 |
Total Lines | 60 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
12 | trait AggregationTrait |
||
13 | { |
||
14 | /** |
||
15 | * @var iterable |
||
16 | */ |
||
17 | protected $iterable; |
||
18 | |||
19 | /** |
||
20 | * Count elements of an iterable. |
||
21 | * |
||
22 | * @return int |
||
23 | */ |
||
24 | 1 | public function count(): int |
|
25 | { |
||
26 | 1 | return i\iterable_count($this->iterable); |
|
1 ignored issue
–
show
|
|||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Reduce all elements to a single value using a callback. |
||
31 | * |
||
32 | * @param callable $callback |
||
33 | * @param mixed $initial |
||
34 | * @return mixed |
||
35 | */ |
||
36 | 1 | public function reduce(callable $callback, $initial = null) |
|
39 | } |
||
40 | |||
41 | /** |
||
42 | * Calculate the sum of all numbers. |
||
43 | * If no elements are present, the result is 0. |
||
44 | * |
||
45 | * @return int|float |
||
46 | */ |
||
47 | 1 | public function sum() |
|
48 | { |
||
49 | 1 | return i\iterable_sum($this->iterable); |
|
1 ignored issue
–
show
|
|||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Return the arithmetic mean. |
||
54 | * If no elements are present, the result is NAN. |
||
55 | * |
||
56 | * @return float |
||
57 | */ |
||
58 | 1 | public function average(): float |
|
59 | { |
||
60 | 1 | return i\iterable_average($this->iterable); |
|
1 ignored issue
–
show
|
|||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Concatenate all elements into a single string. |
||
65 | * |
||
66 | * @param string $glue |
||
67 | * @return string |
||
68 | */ |
||
69 | 2 | public function concat(string $glue = ''): string |
|
72 | } |
||
73 | } |
||
74 |