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

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