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

MapperLocator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 2
cts 2
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\ArrayList;
8
use FRZB\Component\DependencyInjection\Attribute\AsService;
9
use FRZB\Component\RequestMapper\Mapper\MapperInterface as TypeMapper;
10
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
11
12
#[AsService]
13
class MapperLocator implements MapperLocatorInterface
14
{
15
    /** @var ArrayList<string, callable|TypeMapper> */
16
    private readonly ArrayList $mappers;
17
18 19
    public function __construct(
19
        #[TaggedIterator(TypeMapper::class, defaultPriorityMethod: 'getPriority')]
20
        iterable $mappers,
21
    ) {
22 19
        $this->mappers = ArrayList::collect($mappers);
0 ignored issues
show
Bug introduced by
The property mappers is declared read-only in FRZB\Component\RequestMapper\Mapper\MapperLocator.
Loading history...
23
    }
24
25 19
    public function get(string $typeName, mixed $value = null): MapperInterface
26
    {
27 19
        return $this->mappers
28 19
            ->first(static fn (TypeMapper $tm) => $tm->canMap($typeName, $value))
29 19
            ->get()
30
        ;
31
    }
32
}
33