Completed
Push — master ( 122cbf...89c382 )
by
unknown
09:49
created

Propel2Adapter::getSlice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 1
eloc 5
nc 1
nop 2
crap 1
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 3
    public function __construct(ModelCriteria $query)
34
    {
35 3
        $this->query = $query;
36 3
    }
37
38
    /**
39
     * Returns the query.
40
     *
41
     * @return ModelCriteria
42
     */
43 3
    public function getQuery()
44
    {
45 3
        return $this->query;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 1
    public function getNbResults()
52
    {
53 1
        $q = clone $this->getQuery();
54
55 1
        $q->offset(0);
56
57 1
        return $q->count();
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 1
    public function getSlice($offset, $length)
64
    {
65 1
        $q = clone $this->getQuery();
66
67 1
        $q->limit($length);
68 1
        $q->offset($offset);
69
70 1
        return $q->find();
71
    }
72
}
73