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

HelperException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 22
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A noClassProperty() 0 7 2
A noMethodParameter() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\RequestMapper\Exception;
6
7
use JetBrains\PhpStorm\Immutable;
8
use JetBrains\PhpStorm\Pure;
9
10
#[Immutable]
11
final class HelperException extends \LogicException
12
{
13
    private const NO_CLASS_PROPERTY_MESSAGE = 'No property "%s" in class "%s"';
14
    private const NO_METHOD_PARAMETER_MESSAGE = 'Method "%s::%s" has no "%s" parameter';
15
16
    #[Pure]
17
    public static function noClassProperty(string $className, string $propertyName, bool $wrapCallable = true, ?\Throwable $previous = null): callable|self
18
    {
19
        $message = sprintf(self::NO_CLASS_PROPERTY_MESSAGE, $propertyName, $className);
20
        $exception = new self($message, previous: $previous);
21
22
        return $wrapCallable ? static fn () => throw $exception : $exception;
23
    }
24
25
    #[Pure]
26
    public static function noMethodParameter(string $className, string $classMethod, string $parameterName, bool $wrapCallable = true, ?\Throwable $previous = null): callable|self
27
    {
28
        $message = sprintf(self::NO_METHOD_PARAMETER_MESSAGE, $className, $classMethod, $parameterName);
29
        $exception = new self($message, previous: $previous);
30
31
        return $wrapCallable ? static fn () => throw $exception : $exception;
32
    }
33
}
34