DefaultCarrierFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
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