<commit_before><?php

/*
 * This file is part of the Superdesk Web Publisher Content Bundle.
 *
 * Copyright 2015 Sourcefabric z.u. and contributors.
 *
 * For the full copyright and license information, please see the
 * AUTHORS and LICENSE files distributed with this source code.
 *
 * @copyright 2015 Sourcefabric z.ú
 * @license http://www.superdesk.org/license
 */

namespace SWP\Bundle\ContentBundle\Controller;

use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\View\View;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use SWP\Bundle\ContentBundle\Event\RouteEvent;
use SWP\Bundle\ContentBundle\Model\RouteInterface;
use SWP\Bundle\ContentBundle\RouteEvents;
use SWP\Component\Common\Criteria\Criteria;
use SWP\Bundle\ContentBundle\Form\Type\RouteType;
use SWP\Component\Common\Pagination\PaginationData;
use SWP\Component\Common\Response\ResponseContext;
use SWP\Component\Common\Response\SingleResourceResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class RouteController extends FOSRestController
{
    /**
     * Lists current tenant routes.
     *
     * @ApiDoc(
     *     resource=true,
     *     description="Lists current tenant routes",
     *     statusCodes={
     *         200="Returned on success."
     *     },
     *     filters={
     *         {"name"="type", "dataType"="string", "pattern"="collection|content"},
     *         {"name"="sorting", "dataType"="string", "pattern"="[updatedAt]=asc|desc"}
     *     }
     * )
     * @Route("/api/{version}/content/routes/", options={"expose"=true}, defaults={"version"="v1"}, name="swp_api_content_list_routes")
     * @Method("GET")
     */
    public function listAction(Request $request)
    {
        $routeRepository = $this->get('swp.repository.route');

        $routes = $routeRepository->getPaginatedByCriteria(new Criteria([
            'type' => $request->query->get('type', ''),
        ]), $request->query->get('sorting', []), new PaginationData($request));

        return $this->handleView(View::create($this->get('swp_pagination_rep')->createRepresentation($routes, $request), 200));
    }

    /**
     * Show single tenant route.
     *
     * @ApiDoc(
     *     resource=true,
     *     description="Show single tenant route",
     *     statusCodes={
     *         200="Returned on success."
     *     }
     * )
     * @Route("/api/{version}/content/routes/{id}", options={"expose"=true}, defaults={"version"="v1"}, name="swp_api_content_show_routes", requirements={"id"=".+"})
     * @Method("GET")
     */
    public function getAction($id)
    {
        return new SingleResourceResponse($this->findOr404($id));
    }

    /**
     * Delete single tenant route.
     *
     * @ApiDoc(
     *     resource=true,
     *     description="Delete single tenant route",
     *     statusCodes={
     *         204="Returned on success."
     *     }
     * )
     * @Route("/api/{version}/content/routes/{id}", options={"expose"=true}, defaults={"version"="v1"}, name="swp_api_content_delete_routes", requirements={"id"=".+"})
     *
     * @Method("DELETE")
     *
     * @return Response
     */
    public function deleteAction($id)
    {
        $repository = $this->get('swp.repository.route');
        $route = $this->findOr404($id);

        if (null !== $route->getContent()) {
            throw new ConflictHttpException('Route has content attached to it.');
        }

        if (0 < $route->getChildren()->count()) {
            throw new ConflictHttpException('Remove route childrens before removing this route.');
        }
<commit_msg>fix spelling<commit_after><?php

/*
 * This file is part of the Superdesk Web Publisher Content Bundle.
 *
 * Copyright 2015 Sourcefabric z.u. and contributors.
 *
 * For the full copyright and license information, please see the
 * AUTHORS and LICENSE files distributed with this source code.
 *
 * @copyright 2015 Sourcefabric z.ú
 * @license http://www.superdesk.org/license
 */

namespace SWP\Bundle\ContentBundle\Controller;

use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\View\View;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use SWP\Bundle\ContentBundle\Event\RouteEvent;
use SWP\Bundle\ContentBundle\Model\RouteInterface;
use SWP\Bundle\ContentBundle\RouteEvents;
use SWP\Component\Common\Criteria\Criteria;
use SWP\Bundle\ContentBundle\Form\Type\RouteType;
use SWP\Component\Common\Pagination\PaginationData;
use SWP\Component\Common\Response\ResponseContext;
use SWP\Component\Common\Response\SingleResourceResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class RouteController extends FOSRestController
{
    /**
     * Lists current tenant routes.
     *
     * @ApiDoc(
     *     resource=true,
     *     description="Lists current tenant routes",
     *     statusCodes={
     *         200="Returned on success."
     *     },
     *     filters={
     *         {"name"="type", "dataType"="string", "pattern"="collection|content"},
     *         {"name"="sorting", "dataType"="string", "pattern"="[updatedAt]=asc|desc"}
     *     }
     * )
     * @Route("/api/{version}/content/routes/", options={"expose"=true}, defaults={"version"="v1"}, name="swp_api_content_list_routes")
     * @Method("GET")
     */
    public function listAction(Request $request)
    {
        $routeRepository = $this->get('swp.repository.route');

        $routes = $routeRepository->getPaginatedByCriteria(new Criteria([
            'type' => $request->query->get('type', ''),
        ]), $request->query->get('sorting', []), new PaginationData($request));

        return $this->handleView(View::create($this->get('swp_pagination_rep')->createRepresentation($routes, $request), 200));
    }

    /**
     * Show single tenant route.
     *
     * @ApiDoc(
     *     resource=true,
     *     description="Show single tenant route",
     *     statusCodes={
     *         200="Returned on success."
     *     }
     * )
     * @Route("/api/{version}/content/routes/{id}", options={"expose"=true}, defaults={"version"="v1"}, name="swp_api_content_show_routes", requirements={"id"=".+"})
     * @Method("GET")
     */
    public function getAction($id)
    {
        return new SingleResourceResponse($this->findOr404($id));
    }

    /**
     * Delete single tenant route.
     *
     * @ApiDoc(
     *     resource=true,
     *     description="Delete single tenant route",
     *     statusCodes={
     *         204="Returned on success."
     *     }
     * )
     * @Route("/api/{version}/content/routes/{id}", options={"expose"=true}, defaults={"version"="v1"}, name="swp_api_content_delete_routes", requirements={"id"=".+"})
     *
     * @Method("DELETE")
     *
     * @return Response
     */
    public function deleteAction($id)
    {
        $repository = $this->get('swp.repository.route');
        $route = $this->findOr404($id);

        if (null !== $route->getContent()) {
            throw new ConflictHttpException('Route has content attached to it.');
        }

        if (0 < $route->getChildren()->count()) {
            throw new ConflictHttpException('Remove route children before removing this route.');
        }

{'fraction_non_alphanumeric': 0.14842540010325245, 'fraction_numerical': 0.007743933918430563, 'mean_word_length': 3.2205882352941178, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4228081', 'n_tokens_mistral': 2304, 'n_tokens_neox': 2260, 'n_words': 411}