Passed
Push — master ( 882143...e0e0b6 )
by Alexander
07:33
created

CallbackRuleException::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Exception;
6
7
use Throwable;
8
use Yiisoft\FriendlyException\FriendlyExceptionInterface;
9
use Yiisoft\Validator\Result;
10
11
class CallbackRuleException extends \Exception implements FriendlyExceptionInterface
12
{
13 1
    public function __construct($result, $code = 0, Throwable $previous = null)
14
    {
15 1
        $message = sprintf(
16 1
            'Return value of callback must be an instance of %s, %s returned.',
17 1
            Result::class,
18 1
            is_object($result) ? get_class($result) : gettype($result)
19
        );
20
21 1
        parent::__construct($message, $code, $previous);
22 1
    }
23
24
    public function getName(): string
25
    {
26
        return 'Invalid callable return value';
27
    }
28
29
    public function getSolution(): ?string
30
    {
31
        return <<<SOLUTION
32
            The callback must return an instance of \\Yiisoft\\Validator\\Result. An example of a valid callback:
33
                static function (): \\Yiisoft\\Validator\\Result
34
                {
35
                    \$result = new \\Yiisoft\\Validator\\Result();
36
37
                    ...
38
39
                    return \$result;
40
                }
41
        SOLUTION;
42
    }
43
}
44