getParent(); if (null === $parent) { return; } // The parent's ancestors include the task itself: the task is its own parent or a sub-task's child. if ($parent->hasAncestorOrSelf($value)) { $this->context->buildViolation($constraint->loopMessage) ->atPath('parent') ->addViolation(); return; } $plan = $value->getPlan(); $parentPlan = $parent->getPlan(); if (null !== $plan && null !== $parentPlan && $plan->getId() !== $parentPlan->getId()) { $this->context->buildViolation($constraint->otherPlanMessage) ->atPath('parent') ->addViolation(); } } }