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

FiatCurrenciesCollection::check()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 13
ccs 6
cts 6
cp 1
crap 4
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