Passed
Push — master ( be5f7a...5a16c0 )
by Andreas
12:00
created

laterthanorequalValidator::validate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 2
nop 2
dl 0
loc 9
ccs 0
cts 8
cp 0
crap 12
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright CONTENT CONTROL GmbH, http://www.contentcontrol-berlin.de
4
 */
5
6
namespace midcom\datamanager\validation;
7
8
use Symfony\Component\Validator\Constraint;
9
use Symfony\Component\Validator\ConstraintValidator;
10
11
class laterthanorequalValidator extends ConstraintValidator
12
{
13
    public function validate($value, Constraint $constraint) : void
14
    {
15
        $element = $this->context->getObject()->getParent()->get($constraint->value);
16
        $compare = $element->getData();
17
        if ($compare !== null && $value < $compare) {
18
            $label = $element->getConfig()->getOption('label');
19
            $this->context->buildViolation($constraint->message)
20
                ->setParameter('{{ compared_value }}', $label)
21
                ->addViolation();
22
        }
23
    }
24
}
25