| Total Complexity | 11 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | final class IntegerList implements ListType |
||
| 18 | { |
||
| 19 | /** @var int[] */ |
||
| 20 | private $elements = []; |
||
| 21 | |||
| 22 | /** @param mixed[] $elements */ |
||
| 23 | 8 | public function __construct(iterable $elements = []) |
|
| 33 | } |
||
| 34 | 4 | } |
|
| 35 | |||
| 36 | 12 | public function count(): int |
|
| 37 | { |
||
| 38 | 12 | return count($this->elements); |
|
| 39 | } |
||
| 40 | |||
| 41 | 9 | public function isEmpty(): bool |
|
| 42 | { |
||
| 43 | 9 | return $this->count() === 0; |
|
| 44 | } |
||
| 45 | |||
| 46 | 3 | public function isNotEmpty(): bool |
|
| 47 | { |
||
| 48 | 3 | return !$this->isEmpty(); |
|
| 49 | } |
||
| 50 | |||
| 51 | 4 | public function sum(): int |
|
| 52 | { |
||
| 53 | 4 | return (int) array_sum($this->elements); |
|
| 54 | } |
||
| 55 | |||
| 56 | 3 | public function average(): float |
|
| 57 | { |
||
| 58 | 3 | if ($this->isEmpty()) { |
|
| 59 | 1 | return 0.0; |
|
| 60 | } |
||
| 61 | |||
| 62 | 2 | return $this->sum() / $this->count(); |
|
| 63 | } |
||
| 64 | |||
| 65 | /** @return ArrayIterator|int[] */ |
||
| 66 | 3 | public function getIterator(): ArrayIterator |
|
| 69 | } |
||
| 70 | } |
||
| 71 |