Passed
Push — main ( a74a35...8a07cd )
by Fractal
03:04
created

ArrayMapper::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\RequestMapper\Mapper;
6
7
use Fp\Collections\Entry;
8
use Fp\Collections\HashMap;
9
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
10
11
#[AutoconfigureTag(MapperInterface::class)]
12
class ArrayMapper implements MapperInterface
13
{
14 1
    public function __invoke(string $typeName, array $value, array $parameters = []): array
15
    {
16 1
        return HashMap::collect($parameters[key($value)] ?? [])
17 1
            ->map(static fn (Entry $paramEntry) => $value[$paramEntry->key])
18 1
            ->map(fn (Entry $paramEntry) => ($this)($paramEntry->value, $parameters[key($value)][$paramEntry->key] ?? []))
19 1
            ->toAssocArray()
20 1
            ->get()
21
        ;
22
    }
23
24 19
    public function canMap(string $typeName, mixed $value = null): bool
25
    {
26 19
        return \is_array($value) && 'array' === $typeName;
27
    }
28
29 1
    public static function getPriority(): int
30
    {
31 1
        return 4;
32
    }
33
}
34