Selectable   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 41
ccs 8
cts 12
cp 0.6667
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A getItems() 0 6 1
A count() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineModule\Paginator\Adapter;
6
7
use Doctrine\Common\Collections\Criteria;
8
use Doctrine\Common\Collections\Selectable as DoctrineSelectable;
9
use Laminas\Paginator\Adapter\AdapterInterface;
10
use function count;
11
12
/**
13
 * Provides a wrapper around a Selectable object
14
 *
15
 * @link    http://www.doctrine-project.org/
16
 */
17
class Selectable implements AdapterInterface
18
{
19
    /** @var DoctrineSelectable */
20
    protected $selectable;
21
22
    /** @var Criteria */
23
    protected $criteria;
24
25
    /**
26
     * Create a paginator around a Selectable object. You can also provide an optional Criteria object with
27
     * some predefined filters
28
     */
29
    public function __construct(DoctrineSelectable $selectable, ?Criteria $criteria = null)
30
    {
31
        $this->selectable = $selectable;
32
        $this->criteria   = $criteria ? clone $criteria : new Criteria();
33
    }
34
35
    /**
36
     * {@inheritDoc}
37
     */
38 4
    public function getItems($offset, $itemCountPerPage)
39
    {
40 4
        $this->criteria->setFirstResult($offset)->setMaxResults($itemCountPerPage);
41
42 4
        return $this->selectable->matching($this->criteria)->toArray();
43
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48 1
    public function count()
49
    {
50 1
        $criteria = clone $this->criteria;
51
52 1
        $criteria->setFirstResult(null);
53 1
        $criteria->setMaxResults(null);
54
55 1
        return count($this->selectable->matching($criteria));
56
    }
57
}
58