Test Failed
Push — main ( 8bbfd5...5b42e4 )
by Fractal
03:27
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))
0 ignored issues
show
Bug introduced by
It seems like FRZB\Component\RequestMa...MapperFound($exception) can also be of type FRZB\Component\RequestMa...nMapperLocatorException; however, parameter $fallback of Fp\Functional\Option\Option::getOrThrow() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
            ->getOrThrow(/** @scrutinizer ignore-type */ ExceptionMapperLocatorException::noMapperFound($exception))
Loading history...
29
        ;
30
    }
31
}
32