Completed
Push — master ( 8400ab...233003 )
by
unknown
02:27
created

DoctrineODMMongoDBAdapter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 44
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getQueryBuilder() 0 4 1
A getNbResults() 0 4 1
A getSlice() 0 8 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 Doctrine\ODM\MongoDB\Query\Builder;
15
16
/**
17
 * DoctrineODMMongoDBAdapter.
18
 *
19
 * @author Pablo Díez <[email protected]>
20
 */
21
class DoctrineODMMongoDBAdapter implements AdapterInterface
22
{
23
    private $queryBuilder;
24
25
    /**
26
     * Constructor.
27
     *
28
     * @param Builder $queryBuilder A DoctrineMongo query builder.
29
     */
30
    public function __construct(Builder $queryBuilder)
31
    {
32
        $this->queryBuilder = $queryBuilder;
33
    }
34
35
    /**
36
     * Returns the query builder.
37
     *
38
     * @return Builder The query builder.
39
     */
40
    public function getQueryBuilder()
41
    {
42
        return $this->queryBuilder;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getNbResults()
49
    {
50
        return $this->queryBuilder->getQuery()->count();
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getSlice($offset, $length)
57
    {
58
        return $this->queryBuilder
59
            ->limit($length)
60
            ->skip($offset)
61
            ->getQuery()
62
            ->execute();
63
    }
64
}
65