Issues (31)

ExceptionMapper/ExceptionMapperLocator.php (2 issues)

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
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::notFound($exception))
0 ignored issues
show
It seems like FRZB\Component\RequestMa...n::notFound($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::notFound($exception))
Loading history...
29
        ;
30
    }
31
}
32