PaginatesData::createSelectablePaginator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 4
1
<?php
2
3
namespace Nord\Lumen\Core\Traits;
4
5
use Doctrine\Common\Collections\Collection;
6
use Doctrine\Common\Collections\Criteria;
7
use Doctrine\Common\Collections\Selectable;
8
use Doctrine\ORM\QueryBuilder;
9
use League\Fractal\Pagination\PagerfantaPaginatorAdapter;
10
use Pagerfanta\Adapter\AdapterInterface;
11
use Pagerfanta\Adapter\ArrayAdapter;
12
use Pagerfanta\Adapter\DoctrineCollectionAdapter;
13
use Pagerfanta\Adapter\DoctrineORMAdapter;
14
use Pagerfanta\Adapter\DoctrineSelectableAdapter;
15
use Pagerfanta\Exception\NotValidCurrentPageException;
16
use Pagerfanta\Pagerfanta;
17
18
trait PaginatesData
19
{
20
    /**
21
     * @param array $array
22
     * @param int   $page
23
     * @param int   $count
24
     *
25
     * @return PagerfantaPaginatorAdapter
26
     */
27
    private function createArrayPaginator(array $array, $page, $count)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
28
    {
29
        return $this->createPaginator(new ArrayAdapter($array), $page, $count);
30
    }
31
32
    /**
33
     *
34
     * @param QueryBuilder $queryBuilder
35
     * @param int          $page
36
     * @param int          $count
37
     *
38
     * @return PagerfantaPaginatorAdapter
39
     */
40
    private function createQueryBuilderPaginator(QueryBuilder $queryBuilder, $page, $count)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
41
    {
42
        return $this->createPaginator(new DoctrineORMAdapter($queryBuilder), $page, $count);
43
    }
44
45
    /**
46
     * @param Collection $collection
47
     * @param int        $page
48
     * @param int        $count
49
     *
50
     * @return PagerfantaPaginatorAdapter
51
     */
52
    private function createCollectionPaginator(Collection $collection, $page, $count)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
53
    {
54
        return $this->createPaginator(new DoctrineCollectionAdapter($collection), $page, $count);
55
    }
56
57
    /**
58
     * @param Selectable $selectable
59
     * @param Criteria   $criteria
60
     * @param int        $page
61
     * @param int        $count
62
     *
63
     * @return PagerfantaPaginatorAdapter
64
     */
65
    private function createSelectablePaginator(Selectable $selectable, Criteria $criteria, $page, $count)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
66
    {
67
        return $this->createPaginator(new DoctrineSelectableAdapter($selectable, $criteria), $page, $count);
68
    }
69
70
    /**
71
     * @param AdapterInterface $adapter
72
     * @param int              $page
73
     * @param int              $count
74
     *
75
     * @return PagerfantaPaginatorAdapter
76
     */
77
    private function createPaginator(AdapterInterface $adapter, $page, $count)
78
    {
79
        $pager = new Pagerfanta($adapter);
80
81
        try {
82
            $pager->setMaxPerPage($count)->setCurrentPage($page);
83
        } catch (NotValidCurrentPageException $e) {
0 ignored issues
show
Bug introduced by
The class Pagerfanta\Exception\NotValidCurrentPageException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
84
            // Do nothing, because we don't care ...
85
        }
86
87
        return new PagerfantaPaginatorAdapter($pager, function ($page) {
88
            return "page={$page}";
89
        });
90
    }
91
}
92