public function removeTeamFromPool(Pool $pool, Team $team) { $isClear = true; // Delete the games where this team plays /** @var Game $game */ foreach ($pool->getGames() as $game) { if ($game->hasTeam($team)) { if ($game->isPlayed()) { $isClear = false; } else { $pool->removeGame($game); $this->em->remove($game); } } } // If the team is not playing anymore, remove it from the pool if ($isClear) { $pool->removeTeam($team); } $this->em->flush(); return $isClear; }