DefaultCarrierFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 21
ccs 10
cts 10
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createCollection() 0 4 1
A create() 0 5 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inspirum\Balikobot\Model\Carrier;
6
7
use Inspirum\Balikobot\Definitions\Version;
8
use Inspirum\Balikobot\Model\Method\MethodFactory;
9
use function array_filter;
10
use function array_map;
11
use function array_values;
12
13
final class DefaultCarrierFactory implements CarrierFactory
14
{
15 25
    public function __construct(
16
        private readonly MethodFactory $methodFactory,
17
    ) {
18 25
    }
19
20
    /** @inheritDoc */
21 9
    public function create(string $carrier, array $data): Carrier
22
    {
23 9
        return new DefaultCarrier($carrier, $data['name'], array_map(fn (array $methods) => $this->methodFactory->createCollection($methods), array_filter([
24 9
            Version::V2V1 => $data['methods'] ?? [],
25 9
            Version::V2V2 => $data['v2_methods'] ?? [],
26 9
        ])));
27
    }
28
29
    /** @inheritDoc */
30 6
    public function createCollection(array $data): CarrierCollection
31
    {
32 6
        return new DefaultCarrierCollection(
33 6
            array_values(array_map(fn (array $carrier): Carrier => $this->create($carrier['slug'], $carrier), $data['carriers'])),
34 6
        );
35
    }
36
}
37