KnpPaginatorAdapter::getResults()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php
2
3
namespace KGzocha\Bundle\SearcherBundle\Context;
4
5
use KGzocha\Searcher\Context\Doctrine\QueryBuilderSearchingContext;
6
use KGzocha\Searcher\Context\SearchingContextInterface;
7
use Knp\Component\Pager\PaginatorInterface;
8
9
/**
10
 * @author Krzysztof Gzocha <[email protected]>
11
 */
12
class KnpPaginatorAdapter implements SearchingContextInterface
13
{
14
    /**
15
     * @var PaginatorInterface
16
     */
17
    private $paginator;
18
19
    /**
20
     * @var QueryBuilderSearchingContext
21
     */
22
    private $searchingContext;
23
24
    /**
25
     * @var int
26
     */
27
    private $page;
28
29
    /**
30
     * @var int
31
     */
32
    private $limit;
33
34
    /**
35
     * @var array
36
     */
37
    private $options;
38
39
    /**
40
     * @param PaginatorInterface           $paginator
41
     * @param QueryBuilderSearchingContext $searchingContext
42
     */
43 1
    public function __construct(
44
        PaginatorInterface $paginator,
45
        QueryBuilderSearchingContext $searchingContext
46
    ) {
47 1
        $this->paginator = $paginator;
48 1
        $this->searchingContext = $searchingContext;
49 1
        $this->page = 1;
50 1
        $this->limit = 50;
51 1
        $this->options = [];
52 1
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 1
    public function getQueryBuilder()
58
    {
59 1
        return $this->searchingContext->getQueryBuilder();
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 1
    public function getResults()
66
    {
67 1
        return $this->paginator->paginate(
68 1
            $this->getQueryBuilder(),
69 1
            $this->page,
70 1
            $this->limit,
71 1
            $this->options
72
        );
73
    }
74
75
    /**
76
     * @param int $page
77
     */
78 1
    public function setPage($page)
79
    {
80 1
        $this->page = $page;
81 1
    }
82
83
    /**
84
     * @param int $limit
85
     */
86 1
    public function setLimit($limit)
87
    {
88 1
        $this->limit = $limit;
89 1
    }
90
91
    /**
92
     * @param array $options
93
     */
94 1
    public function setOptions(array $options = [])
95
    {
96 1
        $this->options = $options;
97 1
    }
98
}
99