Completed
Push — development ( daed94...13a157 )
by Thomas
18s
created

PersistedWaypointValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Oc\Validator\Constraints;
4
5
use Oc\GeoCache\Persistence\GeoCache\GeoCacheService;
6
use Symfony\Component\Validator\Constraint;
7
8
class PersistedWaypointValidator extends WaypointValidator
9
{
10
    /**
11
     * @var GeoCacheService
0 ignored issues
show
introduced by
GeoCacheService => \Oc\GeoCache\Persistence\GeoCache\GeoCacheService
Loading history...
12
     */
13
    private $geoCacheService;
14
15
    /**
16
     * PersistedWaypointValidator constructor.
17
     *
18
     * @param GeoCacheService $geoCacheService
0 ignored issues
show
introduced by
GeoCacheService => \Oc\GeoCache\Persistence\GeoCache\GeoCacheService
Loading history...
19
     */
20
    public function __construct(GeoCacheService $geoCacheService)
21
    {
22
        $this->geoCacheService = $geoCacheService;
23
    }
24
25
    /**
26
     * Checks if the passed value is valid.
27
     *
28
     * @param mixed $waypoint The value that should be validated
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter name; 1 found
Loading history...
Coding Style Documentation introduced by
Parameter comment must end with a full stop
Loading history...
29
     * @param Constraint $constraint The constraint for the validation
0 ignored issues
show
Coding Style Documentation introduced by
Parameter comment must end with a full stop
Loading history...
introduced by
Constraint => \Symfony\Component\Validator\Constraint
Loading history...
30
     *
31
     * @return bool
32
     */
33
    public function validate($waypoint, Constraint $constraint)
34
    {
35
        $valid = parent::validate($waypoint, $constraint);
36
37
        if (!$valid) {
38
            return false;
39
        }
40
41
        $geoCache = $this->geoCacheService->fetchByWaypoint($waypoint);
42
43
        if ($geoCache === null) {
44
            $this->context->buildViolation($constraint->messageNotFound)
45
                ->setParameter('%waypoint%', $waypoint)
46
                ->addViolation();
47
        }
48
49
        return true;
50
    }
51
}
52