sarnado /
converter
| 1 | <?php |
||
| 2 | |||
| 3 | |||
| 4 | namespace Sarnado\Converter\Collections; |
||
| 5 | |||
| 6 | |||
| 7 | use Sarnado\Converter\Objects\CryptoExchangeObject; |
||
| 8 | use Tightenco\Collect\Support\Collection; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Class CryptoExchangesCollection |
||
| 12 | * @package Sarnado\Converter\Collections |
||
| 13 | */ |
||
| 14 | class CryptoExchangesCollection extends Collection |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * CryptoRatesCollection constructor. |
||
| 18 | * @param array $data |
||
| 19 | */ |
||
| 20 | 24 | public function __construct(array $data = []) |
|
| 21 | { |
||
| 22 | 24 | if ($this->check($data)) |
|
| 23 | { |
||
| 24 | 12 | parent::__construct($data); |
|
| 25 | } |
||
| 26 | else |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 27 | { |
||
| 28 | 12 | throw new \InvalidArgumentException('Item from array must be instance of CryptoExchangeObject'); |
|
| 29 | } |
||
| 30 | 12 | } |
|
| 31 | |||
| 32 | /** |
||
| 33 | * @param array $data |
||
| 34 | * @return bool |
||
| 35 | */ |
||
| 36 | 24 | private function check(array $data): bool |
|
| 37 | { |
||
| 38 | 24 | if (!empty($data)) |
|
| 39 | { |
||
| 40 | 21 | foreach ($data as $item) |
|
| 41 | { |
||
| 42 | 21 | if (!($item instanceof CryptoExchangeObject)) |
|
| 43 | { |
||
| 44 | 15 | return false; |
|
| 45 | } |
||
| 46 | } |
||
| 47 | } |
||
| 48 | 12 | return true; |
|
| 49 | } |
||
| 50 | } |
||
| 51 |