Test Failed
Push — main ( 8bbfd5...5b42e4 )
by Fractal
03:27
created

PropertyMapperLocatorException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 13
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A throwMapperNotFound() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\RequestMapper\Exception;
6
7
use JetBrains\PhpStorm\Immutable;
8
9
#[Immutable]
10
final class PropertyMapperLocatorException extends \LogicException
11
{
12
    private const DEFAULT_NO_MAPPER_FOUND_MESSAGE = 'Mapper not found for %s::%s';
13
14
    public static function throwMapperNotFound(\ReflectionProperty $property, bool $wrapCallable = true, ?\Throwable $previous = null): callable|self
15
    {
16
        $className = $property->getDeclaringClass()->getName();
17
        $propertyName = $property->getName();
18
        $message = sprintf(self::DEFAULT_NO_MAPPER_FOUND_MESSAGE, $className, $propertyName);
19
        $exception = new self($message, previous: $previous);
20
21
        return $wrapCallable ? static fn () => throw $exception : throw $exception;
22
    }
23
}
24