Passed
Push — master ( a9d357...8e355c )
by Alexander
02:33
created

CallbackRuleException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 21
ccs 6
cts 9
cp 0.6667
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSolution() 0 3 1
A getName() 0 3 1
A __construct() 0 9 2
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
    }
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