Issues (7)

src/Collections/FiatCurrenciesCollection.php (1 issue)

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