| Conditions | 4 |
| Paths | 4 |
| Total Lines | 21 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 24 | public static function validate($object, ExecutionContextInterface $context) |
||
| 25 | { |
||
| 26 | if (!method_exists($object, 'getParent')) { |
||
| 27 | return; |
||
| 28 | } |
||
| 29 | |||
| 30 | $tempObject = $object->getParent(); |
||
| 31 | |||
| 32 | while ($tempObject !== null) { |
||
| 33 | if ($tempObject === $object) { |
||
| 34 | $context->buildViolation( |
||
| 35 | 'Circular reference error. ' |
||
| 36 | . 'An object can not reference with a parent to itself nor to an ancestor of itself' |
||
| 37 | ) |
||
| 38 | ->atPath('parent') |
||
| 39 | ->addViolation(); |
||
| 40 | |||
| 41 | break; |
||
| 42 | } |
||
| 43 | |||
| 44 | $tempObject = $tempObject->getParent(); |
||
| 45 | } |
||
| 48 |