private function checkDuplicity(Category $category) { $duplicate = $this->repository->findOneBy(['path' => $category->getPath()]); if ($duplicate !== null) { throw new EntityDuplicateException(sprintf('Category with path %s already exists.', $category->getPath())); } }