Passed
Push — master ( fa5f59...70a733 )
by Anthony
03:11
created

UserLogsRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
dl 0
loc 21
rs 10
c 1
b 0
f 1
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A findAllPaginated() 0 14 3
1
<?php
2
3
namespace PiouPiou\RibsAdminBundle\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
use Doctrine\ORM\Tools\Pagination\Paginator;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\Tools\Pagination\Paginator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
8
9
class UserLogsRepository extends EntityRepository
10
{
11
    /**
12
     * @param int $page
13
     * @param int $max_per_page
14
     * @return Paginator
15
     */
16
    public function findAllPaginated(int $page, int $max_per_page): Paginator
17
    {
18
        $qb = $this->createQueryBuilder('l')->orderBy('l.created_at', 'DESC');
19
        $query = $qb->getQuery();
20
21
        $first_result = ($page - 1) * $max_per_page;
22
        $query->setFirstResult($first_result)->setMaxResults($max_per_page);
23
        $paginator = new Paginator($query);
24
25
        if (($paginator->count() <= $first_result) && $page != 1) {
26
            throw new NotFoundHttpException('La page demandée n\'existe pas.');
27
        }
28
29
        return $paginator;
30
    }
31
}
32