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

CryptoExchangesCollection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 35
ccs 11
cts 11
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 13 4
A __construct() 0 9 2
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