DefaultCountryFactory::createCollection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inspirum\Balikobot\Model\Country;
6
7
use function array_map;
8
use function array_values;
9
use function is_array;
10
11
final class DefaultCountryFactory implements CountryFactory
12
{
13
    /** @inheritDoc */
14 2
    public function create(array $data): Country
15
    {
16 2
        return new DefaultCountry(
17 2
            [
18 2
                'cs' => $data['name_cz'],
19 2
                'en' => $data['name_en'],
20 2
            ],
21 2
            $data['iso_code'],
22 2
            $data['currency'],
23 2
            is_array($data['phone_prefix']) ? array_values($data['phone_prefix']) : [$data['phone_prefix']],
24 2
            $data['continent'],
25 2
        );
26
    }
27
28
    /** @inheritDoc */
29 2
    public function createCollection(array $data): CountryCollection
30
    {
31 2
        return new DefaultCountryCollection(
32 2
            array_map(fn (array $country): Country => $this->create($country), $data['countries'] ?? []),
33 2
        );
34
    }
35
36
    /** @inheritDoc */
37 2
    public function createCodeCollection(array $data): array
38
    {
39 2
        return $data['countries'] ?? [];
40
    }
41
42
    /** @inheritDoc */
43 2
    public function createCodCountryCollection(array $data): array
44
    {
45 2
        $codCountries = [];
46 2
        foreach ($data['cod_countries'] ?? [] as $countryCode => $country) {
47 2
            $codCountries[] = new DefaultCodCountry(
48 2
                $countryCode,
49 2
                $country['currency'],
50 2
                $country['max_price'],
51 2
            );
52
        }
53
54 2
        return $codCountries;
55
    }
56
}
57