예제 #1
0
 /**
  * @param string $id
  * @return Game
  * @throws \Exception
  */
 public function deleteGame($id)
 {
     try {
         $game = $this->gameRepository->find($id);
         if (!$game instanceof Game) {
             throw new \InvalidArgumentException('Game not found');
         }
         // recalculate elo
         $p1 = $game->getPlayer1();
         $p2 = $game->getPlayer2();
         $p1->addElo($game->getPlayer1Elochange());
         $p2->addElo($game->getPlayer2Elochange());
         $this->save($p1, false);
         $this->save($p2, false);
         // delete game
         $this->gameRepository->getManager()->remove($game);
         $this->gameRepository->getManager()->flush();
         return $game;
     } catch (\Exception $e) {
         throw $e;
     }
 }