Passed
Push — master ( 8884a6...674cbd )
by sarnado
02:38
created

FiatCurrenciesCollection::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 2
rs 10
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
Coding Style introduced by
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