<commit_before><?php

namespace Qandidate\AppBundle\Controller;

use Qandidate\Api;
use Qandidate\GameRepository;
use Qandidate\WordList;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class GameController extends Controller
{
    const GOOD_GUESS = 1;
    const BAD_GUESS = 0;

    /**
     * @Route("/", name="start")
     * @Method("GET")
     */
    public function indexAction()
    {
        return $this->render('default/index.html.twig');
    }

    /**
     * @Route("/games", name="new_game")
     * @Method("POST")
     */
    public function newGameAction(Request $request)
    {
        $wordList = WordList::boot();
        $game = Api::bootGame($wordList->getWordAtRandom());

        $this->get('repository.game')->save($game);

        if ($request->isXmlHttpRequest()) {
            return JsonResponse::create(GameRepository::ajaxify($game));
        }

        return $this->redirectToRoute('get_a_game', ['id' => (string) $game]);
    }

    /**
     * @Route("/games", name="all_games")
     * @Method("GET")
     */
    public function allGamesAction(Request $request)
    {
        $games = $this->get('repository.game')->findAll();

        if ($request->isXmlHttpRequest()) {
            return JsonResponse::create(GameRepository::flatten($games));
        }

        return $this->render('default/all_games.html.twig', ['games' => $games]);
    }

    /**
     * @Route("/games/{id}", name="get_a_game")
     * @Method("GET")
     * @ParameterConverter()
     */
    public function getGameAction(Api $game, Request $request)
    {
        if ($request->isXmlHttpRequest()) {
            return JsonResponse::create(GameRepository::ajaxify($game));
        }

        return $this->render('default/game.html.twig', ['game' => $game]);
    }

    /**
     * @Route("/games/{id}", name="guess_character")
     * @Method("POST")
     * @ParameterConverter()
     */
    public function guessCharacterAction(Api $game, Request $request)
    {
        try {
            $isGoodGuess = $game->guessCharacter($request->request->get('char'));
        } catch (\Exception $exception) {
            return JsonResponse::create(
                [
                    'status' => 'error',
                    'message' => $exception->getMessage(),
                ]<commit_msg>fix annotation to ParamConverter typo :)<commit_after><?php

namespace Qandidate\AppBundle\Controller;

use Qandidate\Api;
use Qandidate\GameRepository;
use Qandidate\WordList;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class GameController extends Controller
{
    const GOOD_GUESS = 1;
    const BAD_GUESS = 0;

    /**
     * @Route("/", name="start")
     * @Method("GET")
     */
    public function indexAction()
    {
        return $this->render('default/index.html.twig');
    }

    /**
     * @Route("/games", name="new_game")
     * @Method("POST")
     */
    public function newGameAction(Request $request)
    {
        $wordList = WordList::boot();
        $game = Api::bootGame($wordList->getWordAtRandom());

        $this->get('repository.game')->save($game);

        if ($request->isXmlHttpRequest()) {
            return JsonResponse::create(GameRepository::ajaxify($game));
        }

        return $this->redirectToRoute('get_a_game', ['id' => (string) $game]);
    }

    /**
     * @Route("/games", name="all_games")
     * @Method("GET")
     */
    public function allGamesAction(Request $request)
    {
        $games = $this->get('repository.game')->findAll();

        if ($request->isXmlHttpRequest()) {
            return JsonResponse::create(GameRepository::flatten($games));
        }

        return $this->render('default/all_games.html.twig', ['games' => $games]);
    }

    /**
     * @Route("/games/{id}", name="get_a_game")
     * @Method("GET")
     * @ParamConverter()
     */
    public function getGameAction(Api $game, Request $request)
    {
        if ($request->isXmlHttpRequest()) {
            return JsonResponse::create(GameRepository::ajaxify($game));
        }

        return $this->render('default/game.html.twig', ['game' => $game]);
    }

    /**
     * @Route("/games/{id}", name="guess_character")
     * @Method("POST")
     * @ParamConverter()
     */
    public function guessCharacterAction(Api $game, Request $request)
    {
        try {
            $isGoodGuess = $game->guessCharacter($request->request->get('char'));
        } catch (\Exception $exception) {
            return JsonResponse::create(
                [
                    'status' => 'error',
                    'message' => $exception->getMessage(),
                ]
{'fraction_non_alphanumeric': 0.1602921391504901, 'fraction_numerical': 0.000768787238131847, 'mean_word_length': 2.7819767441860463, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6877964', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1473, 'n_words': 239}