FieldComparisonValidatorTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 14 2
1
<?php
2
3
namespace Bdf\Form\Constraint;
4
5
use Bdf\Form\ElementInterface;
6
use Bdf\Form\Util\FieldPath;
7
use Symfony\Component\Validator\Constraint;
8
9
/**
10
 * Handle FieldComparisonTrait constraints
11
 * The class must extends a subclass of AbstractComparisonValidator
12
 */
13
trait FieldComparisonValidatorTrait
14
{
15
    /**
16
     * {@inheritdoc}
17
     *
18
     * @psalm-suppress UndefinedMagicPropertyFetch
19
     * @psalm-suppress UndefinedMagicPropertyAssignment
20
     *
21
     * @return void
22
     */
23 8
    public function validate($value, Constraint $constraint)
24
    {
25
        /** @var FieldComparisonTrait $constraint */
26
        /** @var ElementInterface $element */
27 8
        $element = $this->context->getRoot()->get();
28 8
        $field = $constraint->field;
29
30 8
        if (!$field instanceof FieldPath) {
31 8
            $field = FieldPath::parse($field);
32
        }
33
34 8
        $constraint->value = $field->value($element);
35
36 8
        parent::validate($value, $constraint);
37 8
    }
38
}
39