/**
  * @param $userId
  * @param $title
  * @param null|string $description
  * @param null|float $hourlyRate
  * @param null|int $id
  * @return Project
  *
  * @throws ProjectNotFoundException
  * @throws UserNotFoundException
  * @throws ValidationException
  */
 public function saveProject($userId, $title, $description = null, $hourlyRate = null, $id = null)
 {
     if ($id !== null) {
         $project = $this->projectRepository->getProject($id, $userId);
         if ($project === null) {
             throw new ProjectNotFoundException();
         }
     } else {
         $project = new Project();
     }
     $user = $this->entityManager->getRepository('AppBundle:User')->find($userId);
     if ($user === null) {
         throw new UserNotFoundException();
     }
     $project->setTitle($title);
     $project->setDescription($description);
     $project->setHourlyRate($hourlyRate);
     $project->setUser($user);
     $errors = $this->validator->validate($project);
     if ($errors->count() > 0) {
         throw new ValidationException($errors);
     }
     $this->projectRepository->saveProject($project);
     return ProjectDTO::withEntity($project);
 }