Passed
Push — develop ( 605aab...b17d99 )
by Stone
06:54 queued 11s
created

PagePagination   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A nextPage() 0 14 4
1
<?php
2
3
namespace App\Pagination;
4
5
use Doctrine\ORM\Tools\Pagination\Paginator;
6
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
7
8
class PagePagination
9
{
10
11
    /**
12
     * Take a paginator list, the actual page and the number of displayed elements
13
     * checks and returns the next page or 0 if we are at the end
14
     * @param Paginator $list
15
     * @param int $page
16
     * @param int $displayedNumber
17
     * @return int
18
     */
19
    public function nextPage(Paginator $list, int $page, int $displayedNumber)
20
    {
21
        $totalList = $list->count();
22
23
        if ($totalList > 0 && $page > ceil($totalList / $displayedNumber)) {
24
            throw new NotFoundHttpException("Page does not exist");
25
        }
26
27
        $nextPage = 0;
28
        if (!($page + 1 > ceil($totalList / $displayedNumber))) {
29
            $nextPage = $page + 1;
30
        }
31
32
        return $nextPage;
33
    }
34
35
}