textId; $text = $this->textRepo->find($textId); if ($text === null) { throw new DomainException("Text with id: $textId doesnt exist"); } if ($request->parentNodeId === null) { return $this->nodeRepo->create(new CreateNodeDto( text: $text, title: $request->title, parentNode: null, )); } $parentNodeId = $request->parentNodeId; $parentNode = $this->nodeRepo->find($parentNodeId); if ($parentNode === null) { throw new DomainException("Node with id: $parentNodeId doesnt exist"); } return $this->nodeRepo->create(new CreateNodeDto( text: $text, title: $request->title, parentNode: $parentNode, )); } }