Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
5 / 5
PagingHandler
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
5 / 5
 handle
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
5 / 5
<?php
namespace App\Handler;
use Symfony\Component\HttpFoundation\Request;
class PagingHandler
{
    public function handle(Request $request)
    {
        $startParam = $request->query->get('start');
        $limitParam = $request->query->get('limit');
        if($startParam > 100 || $limitParam > 100)
        {
            // SI LES ITEMS DEMANDÉS SONT TROP NOMBREUX, ON LANCE UNE EXCEPTION !
            throw new \Exception('Too many items requested. 100 max.');
            // MÉTHODE POUR GÉNÉRER DES MESSAGES D'ERREURS TWIG PAR EXEMPLE DANS UN SERVICE OU PLUS GÉNÉRALEMENT EN DEHORS D'UN CONTROLLER
            // $request->getSession()->getFlashBag()->add('error', 'Vous ne pouvez pas afficher plus de 100 items par page !');
            // COMMENT FAIRE FONCTIONNER CETTE REDIRECTION DEMANDÉE EN DEHORS D'UN CONTROLLER ?
            // return new RedirectResponse('/');
        }
        return array($startParam, $limitParam);
    }
}