security->isGranted('ROLE_USER')) { throw new AccessDeniedException('Access denied: ROLE_USER required.'); } $project = new Project(); $project->setName($name); $project->setCode($code); if (null !== $description) { $project->setDescription($description); } if (null !== $color) { $project->setColor($color); } if (null !== $clientId) { $client = $this->clientRepository->find($clientId); if (null === $client) { throw new InvalidArgumentException(sprintf('Client with ID %d not found.', $clientId)); } $project->setClient($client); } $this->entityManager->persist($project); $this->entityManager->flush(); return json_encode(Serializer::project($project)); } }