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

CryptoCurrenciesCollection   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\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