RelationalPaginatorAdapter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 38
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getItems() 0 9 1
A count() 0 4 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