Completed
Pull Request — master (#90)
by Arnaud
03:14
created

PagerfantaAdminAdapter::getNbResults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 2
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
    private $dataProvider;
14
15
    /**
16
     * @var array
17
     */
18
    private $criteria;
19
20
    /**
21
     * @var array
22
     */
23
    private $orderBy;
24
    
25
    /**
26
     * @var array
27
     */
28
    private $options;
29
    
30
    /**
31
     * PagerfantaAdminAdapter constructor.
32
     *
33
     * @param DataProviderInterface $dataProvider
34
     * @param array                 $criteria
35
     * @param array                 $orderBy
36
     * @param array                 $options
37
     */
38
    public function __construct(
39
        DataProviderInterface $dataProvider,
40
        array $criteria = [],
41
        array $orderBy = [],
42
        array $options = []
43
    ) {
44
        $this->dataProvider = $dataProvider;
45
        $this->criteria = $criteria;
46
        $this->orderBy = $orderBy;
47
        $this->options = $options;
48
    }
49
50
    /**
51
     * Returns the number of results.
52
     *
53
     * @return integer The number of results.
54
     */
55
    public function getNbResults()
56
    {
57
        return $this
58
            ->dataProvider
59
            ->count()
60
        ;
61
    }
62
    
63
    /**
64
     * Returns an slice of the results.
65
     *
66
     * @param integer $offset The offset.
67
     * @param integer $length The length.
68
     *
69
     * @return array|\Traversable The slice.
70
     */
71
    public function getSlice($offset, $length)
72
    {
73
        return $this
74
            ->dataProvider
75
            ->findBy($this->criteria, $this->orderBy, $length, $offset, $this->options)
76
        ;
77
    }
78
}
79