<commit_before><?php
namespace Shorty\Service\UrlBundle\Controller;

use Nocarrier\Hal;
use Shorty\Service\UrlBundle\Controller\ServiceAppController;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\AcceptHeader;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use Shorty\Service\UrlBundle\Entity\Url;
use Shorty\Service\UrlBundle\Entity\Click;

/**
 * @Route("/api/url")
 */
class UrlController extends ServiceAppController
{

	/**
	 * Lists all Urls entities.
     *
	 * @Route("/", name="url_list")
     * @Method("GET")
     * @Template()
	 */
	public function listAction(Request $request)
    {
		$em = $this->getDoctrine()->getManager();

        $query = $em->createQuery('SELECT u FROM ShortyServiceUrlBundle:Url u');
        $urls= $query->getResult();

		$itemsCount = count($em->getRepository('ShortyServiceUrlBundle:Url')->findAll());
        $query = $em->createQuery( 'select u from ShortyServiceUrlBundle:Url u' );
        $urls = $query->getResult();

        $rootData = array(
            'totalRecords' => count($urls)
        );

        $hal = new Hal(
            $this->generateUrl('url_list'),
            $rootData
        );

        foreach($urls as $u) {
            $resource = new Hal(
                $this->generateUrl('url_view', array('id'=>$u->getId()) ),
                $u->toArray()
            );

            $resource->addLink(
                'shortened', 
                $this->container->getParameter('base_href') . $this->generateUrl('redirect',  array('short_url' => $u->getShortUrl() ) )
            );

            $hal->addResource('url', $resource);
        }

        return array(
            'result'  => static::getResult($hal),
        );
    }

	/**
     * Create a new URL
     *<commit_msg>Clean up<commit_after><?php
namespace Shorty\Service\UrlBundle\Controller;

use Nocarrier\Hal;
use Shorty\Service\UrlBundle\Controller\ServiceAppController;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\AcceptHeader;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use Shorty\Service\UrlBundle\Entity\Url;
use Shorty\Service\UrlBundle\Entity\Click;

/**
 * @Route("/api/url")
 */
class UrlController extends ServiceAppController
{

	/**
	 * Lists all Urls entities.
     *
	 * @Route("/", name="url_list")
     * @Method("GET")
     * @Template()
	 */
	public function listAction(Request $request)
    {
		$em = $this->getDoctrine()->getManager();

        $query = $em->createQuery('SELECT u FROM ShortyServiceUrlBundle:Url u');
        $urls= $query->getResult();

		$itemsCount = count($em->getRepository('ShortyServiceUrlBundle:Url')->findAll());
        $query = $em->createQuery( 'select u from ShortyServiceUrlBundle:Url u' );
        $urls = $query->getResult();

        $rootData = array(
            'totalRecords' => count($urls)
        );

        $hal = new Hal(
            $this->generateUrl('url_list'),
            $rootData
        );

        foreach($urls as $u) {
            $resource = new Hal(
                $this->generateUrl('url_view', array('id'=>$u->getId()) ),
                $u->toArray()
            );

            $resource->addLink(
                'shortened', 
                $this->container->getParameter('base_href') . $this->generateUrl('redirect',  array('short_url' => $u->getShortUrl() ) )
            );

            $hal->addResource('url', $resource);
        }

        return array(
            'result'  => static::getResult($hal),
        );
    }

	/**
     * View URL
     *
{'fraction_non_alphanumeric': 0.14972458688032048, 'fraction_numerical': 0.0, 'mean_word_length': 2.7301587301587302, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '3519381', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1161, 'n_words': 191}