TransformerExceptionConstraint   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 13
c 1
b 0
f 0
dl 0
loc 67
ccs 6
cts 6
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultOption() 0 3 1
A withException() 0 6 1
1
<?php
2
3
namespace Bdf\Form\Validator;
4
5
use Exception;
6
use Symfony\Component\Validator\Constraint;
7
8
/**
9
 * @internal
10
 */
11
final class TransformerExceptionConstraint extends Constraint
12
{
13
    const TRANSFORM_ERROR = 'b5acab45-80b0-4808-8784-6577e37ac869';
14
15
    protected static $errorNames = [
16
        self::TRANSFORM_ERROR => 'TRANSFORM_ERROR',
17
    ];
18
19
    /**
20
     * The error message. If null, the exception's message will be taken
21
     *
22
     * @var string|null
23
     */
24
    public $message = null;
25
26
    /**
27
     * The error code
28
     *
29
     * @var string
30
     */
31
    public $code = self::TRANSFORM_ERROR;
32
33
    /**
34
     * The transformer exception
35
     *
36
     * @var Exception
37
     */
38
    public $exception;
39
40
    /**
41
     * Use to validate the exception
42
     * If the closure returns false, the transformer error will be ignored
43
     *
44
     * Note: To change the message or code corresponding to the exception, set code or message attributes on the constraint
45
     *
46
     * @var callable(mixed,TransformerExceptionConstraint,\Bdf\Form\ElementInterface):bool|null
47
     */
48
    public $validationCallback;
49
50
    /**
51
     * Does the transformation error should be ignored ?
52
     * If true, the transformation exception will be ignored
53
     *
54
     * @var bool
55
     */
56
    public $ignoreException = false;
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 434
    public function getDefaultOption()
62
    {
63 434
        return 'exception';
64
    }
65
66
    /**
67
     * Set the exception on the constraint
68
     *
69
     * @param Exception $exception
70
     * @return static
71
     */
72 22
    public function withException(Exception $exception): self
73
    {
74 22
        $constraint = clone $this;
75 22
        $constraint->exception = $exception;
76
77 22
        return $constraint;
78
    }
79
}
80