/** * Validates that the inserted parts assembly * does not contain the current item. This * prevents infinite recursion. * * @param Model $part * * @return bool * * @throws InvalidPartException */ private function validatePart(Model $part) { if ((int) $part->getKey() === (int) $this->getKey()) { $message = 'An item cannot be an assembly of itself.'; throw new InvalidPartException($message); } $list = $part->getAssemblyItemsList(); array_walk_recursive($list, [$this, 'validatePartAgainstList']); return true; }