Total Complexity | 4 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
16 | 1 | class ValidationException extends LogicException |
|
17 | { |
||
18 | |||
19 | 1 | public function __construct( |
|
27 | 1 | } |
|
28 | |||
29 | /** |
||
30 | * Validation exception simple factory |
||
31 | */ |
||
32 | public static function createFromRule( |
||
33 | Rule $rule, |
||
34 | mixed $value = null, |
||
35 | ): self |
||
36 | { |
||
37 | 1 | $arg = $rule->getArgument(); |
|
38 | 1 | $printable = match (true) { |
|
39 | 1 | is_object($arg) => [get_class($arg)], |
|
|
|||
40 | 1 | is_callable($arg) => [get_debug_type($arg)], |
|
41 | 1 | default => (array) $arg, |
|
42 | }; |
||
43 | |||
44 | 1 | return new self( |
|
45 | 1 | $rule->getField(), |
|
46 | ( |
||
47 | 1 | $value |
|
48 | 1 | ? "'" . Strings::truncate(strval($value), 60) . "' is invalid value: " |
|
49 | 1 | : '' |
|
50 | 1 | ) . vsprintf($rule->getMessage(), $printable), |
|
51 | 1 | $rule->getCode(), |
|
52 | ); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Get validation field name |
||
57 | */ |
||
58 | public function getField(): string |
||
61 | } |
||
62 | } |
||
63 |