DefaultZipCodeFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 36
ccs 18
cts 18
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 8 2
A createIterator() 0 3 1
A create() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inspirum\Balikobot\Model\ZipCode;
6
7
use Generator;
8
9
final class DefaultZipCodeFactory implements ZipCodeFactory
10
{
11
    /** @inheritDoc */
12 6
    public function create(string $carrier, ?string $service, array $data): ZipCode
13
    {
14 6
        return new DefaultZipCode(
15 6
            $carrier,
16 6
            $service,
17 6
            $data['zip'] ?? ($data['zip_start'] ?? null),
18 6
            $data['zip_end'] ?? null,
19 6
            $data['city'] ?? null,
20 6
            $data['region'] ?? null,
21 6
            $data['country'] ?? null,
22 6
            (bool) ($data['1B'] ?? false),
23 6
        );
24
    }
25
26
    /** @inheritDoc */
27 6
    public function createIterator(string $carrier, ?string $service, ?string $country, array $data): ZipCodeIterator
28
    {
29 6
        return new DefaultZipCodeIterator($carrier, $service, $this->generate($carrier, $service, $country, $data));
30
    }
31
32
    /**
33
     * @param array<string,mixed> $data
34
     *
35
     * @return \Generator<\Inspirum\Balikobot\Model\ZipCode\ZipCode>
36
     */
37 6
    private function generate(string $carrier, ?string $service, ?string $country, array $data): Generator
38
    {
39 6
        $country = $data['country'] ?? $country;
40
41 6
        foreach ($data['zip_codes'] ?? [] as $item) {
42 6
            $item['country'] ??= $country;
43
44 6
            yield $this->create($carrier, $service, $item);
45
        }
46
    }
47
}
48