Completed
Push — dev ( 4306de...25864c )
by Arnaud
02:52
created

PagerFantaAdminAdapter::getSlice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
crap 1
1
<?php
2
3
namespace LAG\AdminBundle\Pager;
4
5
use LAG\AdminBundle\DataProvider\DataProviderInterface;
6
use Pagerfanta\Adapter\AdapterInterface;
7
8
class PagerFantaAdminAdapter implements AdapterInterface
9
{
10
    /**
11
     * @var DataProviderInterface
12
     */
13
    protected $dataProvider;
14
15
    /**
16
     * @var array
17
     */
18
    protected $criteria;
19
20
    /**
21
     * @var array
22
     */
23
    protected $orderBy;
24
25
    /**
26
     * PagerFantaAdminAdapter constructor.
27
     *
28
     * @param DataProviderInterface $dataProvider
29
     * @param array $criteria
30
     * @param array $orderBy
31
     */
32 5
    public function __construct(DataProviderInterface $dataProvider, $criteria = [], $orderBy = [])
33
    {
34 5
        $this->dataProvider = $dataProvider;
35 5
        $this->criteria = $criteria;
36 5
        $this->orderBy = $orderBy;
37 5
    }
38
39
    /**
40
     * Returns the number of results.
41
     *
42
     * @return integer The number of results.
43
     */
44
    public function getNbResults()
45
    {
46
        $entities = $this
47
            ->dataProvider
48
            ->findBy($this->criteria);
49
        $count = count($entities);
50
        unset($entities);
51
52
        return $count;
53
    }
54
55
    /**
56
     * Returns an slice of the results.
57
     *
58
     * @param integer $offset The offset.
59
     * @param integer $length The length.
60
     *
61
     * @return array|\Traversable The slice.
62
     */
63 5
    public function getSlice($offset, $length)
64
    {
65 5
        return $this
66
            ->dataProvider
67 5
            ->findBy($this->criteria, $this->orderBy, $length, $offset);
68
    }
69
}
70