Issues (7)

src/Collections/CryptoCurrenciesCollection.php (1 issue)

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