DefaultCountryFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 11 2
A createCollection() 0 4 1
A createCodCountryCollection() 0 12 2
A createCodeCollection() 0 3 1
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