__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 26
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 26
ccs 0
cts 0
cp 0
crap 6
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Exception;
6
7
use RuntimeException;
8
use Throwable;
9
use Yiisoft\Validator\RuleHandlerResolver\RuleHandlerContainer;
10
use Yiisoft\Validator\RuleHandlerInterface;
11
use Yiisoft\Validator\RuleHandlerResolverInterface;
12
13 2
/**
14
 * An exception used by {@see RuleHandlerResolverInterface} implementations (e. g., {@see RuleHandlerContainer}) for
15 2
 * the case when a retrieved value is not an object or an object that does not implement {@see RuleHandlerInterface}.
16 2
 */
17
final class RuleHandlerInterfaceNotImplementedException extends RuntimeException
18
{
19
    public function __construct(
20
        /**
21
         * @param mixed A variable retrieved from the container.
22
         */
23
        mixed $value,
24
        /**
25
         * @var int The Exception code.
26
         */
27
        int $code = 0,
28
        /**
29
         * @var Throwable|null The previous throwable used for the exception chaining.
30
         */
31
        ?Throwable $previous = null,
32
    ) {
33
        $type = get_debug_type($value);
34
35
        parent::__construct(
36
            sprintf(
37
                class_exists($type)
38
                    ? 'Handler "%1$s" must implement "%2$s".'
39
                    : 'Expected instance of "%2$s". Got "%1$s".',
40
                $type,
41
                RuleHandlerInterface::class,
42
            ),
43
            $code,
44
            $previous
45
        );
46
    }
47
}
48