Completed
Push — master ( 4a7c7e...b71ec0 )
by Benjamin
02:32
created

RouteExistsValidator::validate()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
c 5
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 3
eloc 9
nc 4
nop 2
1
<?php
2
3
namespace Alpixel\Bundle\MenuBundle\Validator\Constraints;
4
5
use Alpixel\Bundle\MenuBundle\Utils\URLChecker;
6
use Symfony\Component\Validator\Constraint;
7
use Symfony\Component\Validator\ConstraintValidator;
8
9
class RouteExistsValidator extends ConstraintValidator
10
{
11
    private $checker;
12
    private $session;
0 ignored issues
show
Unused Code introduced by
The property $session is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
13
14
    public function __construct(URLChecker $checker)
15
    {
16
        $this->checker = $checker;
17
    }
18
19
    public function validate($value, Constraint $constraint)
20
    {
21
        $match = true;
22
        $code = $this->checker->check($value);
23
        if ($code === URLChecker::URL_NOT_FOUND) {
24
            $match = false;
25
        }
26
27
        if ($match === false) {
28
            $this->context->buildViolation($constraint->message)
29
                ->setParameter('%string%', $value)
30
                ->addViolation();
31
        }
32
    }
33
}
34