<commit_before><?php

namespace AdminBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{

    public function indexAction()
    {
        return $this->render('AdminBundle:Default:index.html.twig');
    }

    /**
     * Get all users
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function getUsersAction()
    {
        $em = $this->getDoctrine()->getManager();
        $users = $em->getRepository('UserBundle:User')->findAll();

        return $this->render('AdminBundle:Default:users.html.twig', array(
            'users' => $users
        ));
    }

    /**
     * Modify the status of an User identified by ID
     *
     * @param $id
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     */
    public function modifyUserStatusAction($id)
    {
        $em = $this->getDoctrine()->getManager();
        $user = $em->getRepository('UserBundle:User')->find($id);

        if($user->isEnabled() == true) {
            $user->setEnabled(false);
        } else {
            $user->setEnabled(true);
        }

        $em->persist($user);
        $em->flush();

        return $this->redirectToRoute('admin_homepage');
    }

    /**
     * Delete an User identified by ID
     *
     * @param $id
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     */
    public function deleteUserAction($id)
    {
        $em = $this->getDoctrine()->getManager();
        $user = $em->getRepository('UserBundle:User')->find($id);

        $em->remove($user);
        $em->flush();

        return $this->redirectToRoute('admin_homepage');
    }

    /**<commit_msg>Cleaned code to use service only to change User status<commit_after><?php

namespace AdminBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{

    public function indexAction()
    {
        return $this->render('AdminBundle:Default:index.html.twig');
    }

    /**
     * Get all users
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function getUsersAction()
    {
        $em = $this->getDoctrine()->getManager();
        $users = $em->getRepository('UserBundle:User')->findAll();

        return $this->render('AdminBundle:Default:users.html.twig', array(
            'users' => $users
        ));
    }

    /**
     * Modify the status of an User identified by ID
     *
     * @param $id
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     */
    public function modifyUserStatusAction($id)
    {
        $status = $this->get('admin.change_user_status');
        $status->changeStatus($id);

        return $this->redirectToRoute('admin_homepage');
    }

    /**
     * Delete an User identified by ID
     *
     * @param $id
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     */
    public function deleteUserAction($id)
    {
        $em = $this->getDoctrine()->getManager();
        $user = $em->getRepository('UserBundle:User')->find($id);

        $em->remove($user);
        $em->flush();

        return $this->redirectToRoute('admin_homepage');
    }

    /**
{'fraction_non_alphanumeric': 0.1469412849677221, 'fraction_numerical': 0.0, 'mean_word_length': 2.4397463002114166, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 44, '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': '818769', 'n_tokens_mistral': 940, 'n_tokens_neox': 921, 'n_words': 163}