<commit_before><?php
/**
 * /src/App/Controller/AuthorController.php
 *
 * @author  TLe, <NAME> <<EMAIL>>
 */
namespace App\Controller;

// Symfony components
use FOS\RestBundle\Context\Context;
use Symfony\Component\DependencyInjection\ContainerInterface;

// 3rd party components
use FOS\RestBundle\Controller\FOSRestController;
use Symfony\Component\HttpFoundation\Request;

/**
 * Class AuthorController
 *
 * @category    REST
 * @package     App\Controller
 * @author      TLe, <NAME> <<EMAIL>>
 */
class AuthorController extends FOSRestController
{
    /**
     * @var \Doctrine\Common\Persistence\ObjectRepository
     */
    protected $repository;

    /**
     * Sets the container.
     *
     * @param ContainerInterface|null $container A ContainerInterface instance or null
     */
    public function setContainer(ContainerInterface $container = null)
    {
        parent::setContainer($container);

        $this->repository = $this->getDoctrine()->getRepository('AppBundle:Author');
    }

    /**
     * todo
     *
     * @param Request $request
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function getAuthorAction(Request $request)
    {
        $populate = (array)$request->get('populate', []);
        $populateAll = array_key_exists('populateAll', $request->query->all());

        $context = $this->getSerializeContext($populate, $populateAll);

        $data = $this->repository->findAll();
        $view = $this->view($data, 200);
        $view->setContext($context);

        return $this->handleView($view);
    }

    /**
     * Helper method to get serialization context for query.
     *
     * @param   array   $populate
     * @param   boolean $populateAll
     *
     * @return  Context
     */
    protected function getSerializeContext(array $populate, $populateAll)
    {
        $bits = explode('\\', $this->repository->getClassName());

        // Determine used default group
        $defaultGroup = $populateAll ? 'Default' : end($bits);

        if (count($populate) === 0 && $populateAll) {
            $associations = array_keys(
                $this->getDoctrine()->getManager()->getClassMetadata('AppBundle:Author')->getAssociationMappings()
            );

            $populate = array_map('ucfirst', $associations);
        }

        // Create context and set used groups
        $context = new Context();
        $context->addGroups(array_merge([$defaultGroup], $populate));
        $context->setSerializeNull(true);

        return $context;
    }
}<commit_msg>Changed AuthorController to use generic Rest controller.<commit_after><?php
/**
 * /src/App/Controller/AuthController.php
 *
 * @author  TLe, <NAME> <<EMAIL>>
 */
namespace App\Controller;

// Application components
use App\Services\Author;

// Sensio components
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;

// Symfony components
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;

/**
 * Class AuthorController
 *
 * @Route("/author")
 *
 * @category    Controller
 * @package     App\Controller
 * @author      TLe, <NAME> <<EMAIL>>
 */
class AuthorController extends Rest
{
    /**
     * Service object for controller.
     *
     * @var Author
     */
    protected $service;

    /**
     * Name of the service that controller uses. This is used on setContainer method to invoke specified service to
     * class context.
     *
     * @var string
     */
    protected $serviceName = 'app.services.author';

    /**
     * This is just for the route config, nothing else...
     *
     * @Route("/")
     *
     * @Method({"GET"})
     *
     * Security("has_role('ROLE_USER')")
     *
     * @param   Request $request
     *
     * @return  Response
     */
    public function find(Request $request)
    {
        return parent::find($request);
    }

    /**
     * This is just for the route config, nothing else...
     *
     * @Route(
     *      "/{id}",
     *      requirements={"id" = "\d+"}
     *  )
     *
     * @Method({"GET"})
     *
     * Security("has_role('ROLE_USER')")
     *
     * @param   Request $request
     * @param   integer $id
     *
     * @return Response
     */
    public function findOne(Request $request, $id = 0)
    {
        return parent::findOne($request, $id);
    }
}
{'fraction_non_alphanumeric': 0.13641462867399595, 'fraction_numerical': 0.0013461969934933811, 'mean_word_length': 2.5951612903225807, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 35, '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': '6599556', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1265, 'n_words': 275}