ComparerNotEmptyValidator::validate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Locastic\SyliusComparerPlugin\Validator\Constraints;
6
7
use Locastic\SyliusComparerPlugin\Utils\ComparerCapacityCheckerInterface;
8
use Symfony\Component\Validator\Constraint;
9
use Symfony\Component\Validator\ConstraintValidator;
10
11
final class ComparerNotEmptyValidator extends ConstraintValidator
12
{
13
    /** @var ComparerCapacityCheckerInterface */
14
    private $capacityChecker;
15
16
    public function __construct(ComparerCapacityCheckerInterface $capacityChecker)
17
    {
18
        $this->capacityChecker = $capacityChecker;
19
    }
20
21
    /**
22
     * Checks if the passed value is valid.
23
     *
24
     * @param mixed $value The value that should be validated
25
     * @param Constraint $constraint The constraint for the validation
26
     */
27
    public function validate($value, Constraint $constraint)
28
    {
29
        if ($this->capacityChecker->isComparerEmpty($value)) {
30
            $this->context->buildViolation($constraint->message)
31
                ->addViolation();
32
        }
33
    }
34
}
35