RelationalPaginatorAdapter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * doctrine-orm-repositories (https://github.com/juliangut/doctrine-orm-repositories).
5
 * Doctrine2 ORM utility entity repositories.
6
 *
7
 * @license MIT
8
 * @link https://github.com/juliangut/doctrine-orm-repositories
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Jgut\Doctrine\Repository\ORM;
15
16
use Doctrine\ORM\Tools\Pagination\Paginator;
17
use Zend\Paginator\Adapter\AdapterInterface;
18
19
/**
20
 * Relational paginator adapter.
21
 */
22
class RelationalPaginatorAdapter implements AdapterInterface
23
{
24
    /**
25
     * @var Paginator
26
     */
27
    protected $paginator;
28
29
    /**
30
     * Adapter constructor.
31
     *
32
     * @param Paginator $paginator
33
     */
34
    public function __construct(Paginator $paginator)
35
    {
36
        $this->paginator = $paginator;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getItems($offset, $itemCountPerPage): array
43
    {
44
        $this->paginator
45
            ->getQuery()
46
            ->setFirstResult($offset)
47
            ->setMaxResults($itemCountPerPage);
48
49
        return $this->paginator->getIterator();
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function count(): int
56
    {
57
        return $this->paginator->count();
58
    }
59
}
60