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

HelperException::noMethodParameter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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