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

PagerfantaAdminAdapter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 71
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getNbResults() 0 7 1
A getSlice() 0 7 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
    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