PagerfantaHandler   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 59
rs 10
wmc 11

8 Methods

Rating   Name   Duplication   Size   Complexity  
A totalPages() 0 3 1
A numberOfItemsPerPage() 0 3 1
A totalItems() 0 3 1
A setItemsPerPage() 0 3 1
A setCurrentPage() 0 3 1
A getCurrentPageResults() 0 3 1
A initializePaginatorHandler() 0 18 4
A count() 0 3 1
1
<?php
2
3
namespace Bugloos\ResponderBundle\PaginatorHandler\Pagerfanta;
4
5
use Bugloos\ResponderBundle\PaginatorHandler\Contract\PaginatorHandlerInterface;
6
use Pagerfanta\Pagerfanta;
7
8
/**
9
 * @author Mojtaba Gheytasi <[email protected]>
10
 */
11
class PagerfantaHandler implements PaginatorHandlerInterface
12
{
13
    private const FETCH_JOIN_COLLECTION = 'fetchJoinCollection';
14
15
    private Pagerfanta $paginatorHandler;
16
17
    public function initializePaginatorHandler($query, int $limit = null, array $options = []): void
18
    {
19
        $fetchJoinCollection = true;
20
21
        if (
22
            array_key_exists(self::FETCH_JOIN_COLLECTION, $options) &&
23
            $options['fetchJoinCollection'] === false
24
        ) {
25
            $fetchJoinCollection = false;
26
        }
27
28
        $adapter = new CustomQueryAdapter($query, $fetchJoinCollection);
29
30
        if ($limit !== null) {
31
            $adapter->setLimit($limit);
32
        }
33
34
        $this->paginatorHandler = new Pagerfanta($adapter);
35
    }
36
37
    public function getCurrentPageResults(): iterable
38
    {
39
        return $this->paginatorHandler->getCurrentPageResults();
40
    }
41
42
    public function totalPages(): int
43
    {
44
        return $this->paginatorHandler->getNbPages();
45
    }
46
47
    public function totalItems(): int
48
    {
49
        return $this->paginatorHandler->getNbResults();
50
    }
51
52
    public function count(): int
53
    {
54
        return \count($this->paginatorHandler->getIterator());
0 ignored issues
show
Bug introduced by
$this->paginatorHandler->getIterator() of type Traversable is incompatible with the type Countable|array expected by parameter $value of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

54
        return \count(/** @scrutinizer ignore-type */ $this->paginatorHandler->getIterator());
Loading history...
55
    }
56
57
    public function numberOfItemsPerPage(): int
58
    {
59
        return $this->paginatorHandler->getMaxPerPage();
60
    }
61
62
    public function setItemsPerPage(int $itemPerPage): void
63
    {
64
        $this->paginatorHandler->setMaxPerPage($itemPerPage);
65
    }
66
67
    public function setCurrentPage(int $page): void
68
    {
69
        $this->paginatorHandler->setCurrentPage($page);
70
    }
71
}
72