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

RouteExistsValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 4
c 5
b 0
f 0
lcom 1
cbo 4
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 14 3
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