Passed
Push — main ( 2dd0b4...7b6409 )
by Fractal
03:40 queued 12s
created

ArrayMapper::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

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 0
cts 6
cp 0
crap 2
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
    public function __invoke(string $typeName, array $value, array $parameters = []): array
15
    {
16
        return HashMap::collect($parameters[key($value)] ?? [])
17
            ->map(static fn (Entry $paramEntry) => $value[$paramEntry->key])
18
            ->map(fn (Entry $paramEntry) => ($this)($paramEntry->value, $parameters[key($value)][$paramEntry->key] ?? []))
19
            ->toAssocArray()
20
            ->get()
21
        ;
22
    }
23
24
    public function canMap(string $typeName, mixed $value = null): bool
25
    {
26
        return \is_array($value) && 'array' === $typeName;
27
    }
28
29
    public static function getPriority(): int
30
    {
31
        return 4;
32
    }
33
}
34