Total Complexity | 8 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | class CryptoRatesCollection extends Collection |
||
14 | { |
||
15 | /** |
||
16 | * CryptoRatesCollection constructor. |
||
17 | * @param array $data |
||
18 | */ |
||
19 | 30 | public function __construct(array $data = []) |
|
20 | { |
||
21 | 30 | if ($this->check($data)) |
|
22 | { |
||
23 | 18 | parent::__construct($data); |
|
24 | } |
||
25 | else |
||
|
|||
26 | { |
||
27 | 12 | throw new \InvalidArgumentException('Item from array must be instance of CryptoRateObject'); |
|
28 | } |
||
29 | 18 | } |
|
30 | |||
31 | /** |
||
32 | * @param array $data |
||
33 | * @return bool |
||
34 | */ |
||
35 | 30 | private function check(array $data): bool |
|
36 | { |
||
37 | 30 | if (!empty($data)) |
|
38 | { |
||
39 | 24 | foreach ($data as $item) |
|
40 | { |
||
41 | 24 | if (!($item instanceof CryptoRateObject)) |
|
42 | { |
||
43 | 16 | return false; |
|
44 | } |
||
45 | } |
||
46 | } |
||
47 | 18 | return true; |
|
48 | } |
||
49 | |||
50 | 6 | public function filterByPair(string $crypto, string $fiat): CryptoRatesCollection |
|
55 | 6 | }); |
|
56 | } |
||
57 | } |
||
58 |