Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
PaginatorRepoTrait
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 paginate
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Helper\Paginator;
6
7use Doctrine\ORM\Query;
8use Doctrine\ORM\Tools\Pagination\Paginator;
9
10trait PaginatorRepoTrait
11{
12    /**
13     * @return Paginator<Query>
14     */
15    public function paginate(
16        Query $dql,
17        int $page = 1,
18        int $limit = 5
19    ): Paginator
20    {
21        /** @var Paginator<Query> $paginator */
22        $paginator = new Paginator($dql);
23
24        $paginator->getQuery()
25            ->setFirstResult($limit * ($page - 1))
26            ->setMaxResults($limit);
27
28        return $paginator;
29    }
30}