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

RouteExistsValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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