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

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