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

CryptoCurrenciesCollection::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\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
Coding Style introduced by
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