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

throwMapperNotFound()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 3
dl 0
loc 8
rs 10
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