Completed
Push — master ( f56ef3...122cbf )
by
unknown
04:46 queued 01:44
created

Propel2Adapter::getSlice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 9.6666
cc 1
eloc 5
nc 1
nop 2
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Pagerfanta package.
5
 *
6
 * (c) Pablo Díez <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Pagerfanta\Adapter;
13
14
use Propel\Runtime\ActiveQuery\ModelCriteria;
15
16
/**
17
 * Propel2Adapter.
18
 *
19
 * @author Raphael YAN <[email protected]>
20
 */
21
class Propel2Adapter implements AdapterInterface
22
{
23
    /**
24
     * @var ModelCriteria $query
25
     */
26
    private $query;
27
28
    /**
29
     * Constructor.
30
     *
31
     * @param ModelCriteria $query
32
     */
33
    public function __construct(ModelCriteria $query)
34
    {
35
        $this->query = $query;
36
    }
37
38
    /**
39
     * Returns the query.
40
     *
41
     * @return ModelCriteria
42
     */
43
    public function getQuery()
44
    {
45
        return $this->query;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getNbResults()
52
    {
53
        $q = clone $this->getQuery();
54
55
        $q->offset(0);
56
57
        return $q->count();
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function getSlice($offset, $length)
64
    {
65
        $q = clone $this->getQuery();
66
67
        $q->limit($length);
68
        $q->offset($offset);
69
70
        return $q->find();
71
    }
72
}
73