Test Failed
Push — main ( 450f80...a11e57 )
by Fractal
02:32
created

HelperException::noClassProperty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
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 HelperException extends \LogicException
11
{
12
    private const NO_CLASS_PROPERTY_MESSAGE = 'No property "%s" in class "%s"';
13
    private const NO_METHOD_PARAMETER_MESSAGE = 'Method "%s::%s" has no "%s" parameter';
14
15
    public static function noClassProperty(string $className, string $propertyName, bool $wrapCallable = true, ?\Throwable $previous = null): callable|self
16
    {
17
        $message = sprintf(self::NO_CLASS_PROPERTY_MESSAGE, $propertyName, $className);
18
        $exception = new self($message, previous: $previous);
19
20
        return $wrapCallable ? static fn () => throw $exception : $exception;
21
    }
22
23
    public static function noMethodParameter(string $className, string $classMethod, string $parameterName, bool $wrapCallable = true, ?\Throwable $previous = null): callable|self
24
    {
25
        $message = sprintf(self::NO_METHOD_PARAMETER_MESSAGE, $className, $classMethod, $parameterName);
26
        $exception = new self($message, previous: $previous);
27
28
        return $wrapCallable ? static fn () => throw $exception : $exception;
29
    }
30
}
31