Conditions | 5 |
Paths | 5 |
Total Lines | 23 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 30 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
18 | public function validate($object, Constraint $constraint) |
||
19 | { |
||
20 | if (!$constraint instanceof InstanceOfConstraint) { |
||
21 | throw new UnexpectedTypeException($constraint, 'Majora\Framework\Validation\Constraint\InstanceOfConstraint'); |
||
22 | } |
||
23 | |||
24 | if (null === $object) { |
||
25 | return; |
||
26 | } |
||
27 | |||
28 | if (!is_object($object)) { |
||
29 | throw new UnexpectedTypeException($object, 'object'); |
||
30 | } |
||
31 | |||
32 | if (!is_a($object, $constraint->class)) { |
||
33 | $this->context |
||
34 | ->buildViolation($constraint->message) |
||
35 | ->setParameter('{{ object_class }}', $this->formatValue(get_class($object))) |
||
36 | ->setParameter('{{ tested_class }}', $this->formatValue($constraint->class)) |
||
37 | ->addViolation() |
||
38 | ; |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 |