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

CryptoCurrenciesCollectionBuilder::build()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 15
ccs 8
cts 8
cp 1
crap 4
rs 10
1
<?php
2
3
4
namespace Sarnado\Converter\Builders;
5
6
7
use Sarnado\Converter\Collections\CryptoCurrenciesCollection;
8
use Sarnado\Converter\Contracts\CollectionBuilderInterface;
9
use Sarnado\Converter\Objects\CryptoCurrencyObject;
10
11
class CryptoCurrenciesCollectionBuilder implements CollectionBuilderInterface
12
{
13
14 9
    public static function build(array $data): CryptoCurrenciesCollection
15
    {
16 9
        $result = [];
17 9
        if (!empty($data))
18
        {
19 9
            foreach ($data as $item)
20
            {
21 9
                if (!is_string($item))
22
                {
23 3
                    throw new \UnexpectedValueException('Not valid item');
24
                }
25 6
                $result[] = new CryptoCurrencyObject($item);
26
            }
27
        }
28 6
        return new CryptoCurrenciesCollection($result);
29
    }
30
}
31