Test Failed
Push — main ( 450f80...a11e57 )
by Fractal
02:32
created

ExceptionMapperLocator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\RequestMapper\ExceptionMapper;
6
7
use Fp\Collections\HashMap;
8
use FRZB\Component\DependencyInjection\Attribute\AsService;
9
use FRZB\Component\RequestMapper\Exception\ExceptionMapperLocatorException;
10
use FRZB\Component\RequestMapper\ExceptionMapper\Mapper\ExceptionMapperInterface;
11
use FRZB\Component\RequestMapper\ExceptionMapper\Mapper\ExceptionMapperInterface as ExceptionMapper;
12
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
13
14
#[AsService]
15
final class ExceptionMapperLocator implements ExceptionMapperLocatorInterface
16
{
17
    private readonly HashMap $mappers;
18
19
    public function __construct(#[TaggedIterator(ExceptionMapperInterface::class, defaultIndexMethod: 'getType')] iterable $mappers)
20
    {
21
        $this->mappers = HashMap::collect($mappers);
0 ignored issues
show
Bug introduced by
The property mappers is declared read-only in FRZB\Component\RequestMa...\ExceptionMapperLocator.
Loading history...
22
    }
23
24
    public function get(\Throwable $exception): ExceptionMapper
25
    {
26
        return $this->mappers
27
            ->get($exception::class)
28
            ->getOrThrow(ExceptionMapperLocatorException::noMapperFound($exception))
29
        ;
30
    }
31
}
32