Passed
Pull Request — master (#631)
by ANTHONIUS
08:16
created

DoctrineMongoLateAdapter::count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 1
b 0
f 1
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Core\Paginator\Adapter;
6
7
8
use Core\Repository\Filter\AbstractPaginationQuery;
9
use Laminas\Paginator\Adapter\AdapterInterface;
10
use Doctrine\ODM\MongoDB\Query\Builder as QueryBuilder;
11
12
/**
13
 * Class DoctrineMongoLateAdapter
14
 *
15
 * TODO: require count to be passed on constructor
16
 * @since 0.36
17
 * @package Core\Paginator\Adapter
18
 */
19
class DoctrineMongoLateAdapter implements AdapterInterface
20
{
21
    /**
22
     * @var QueryBuilder
23
     */
24
    private QueryBuilder $queryBuilder;
25
26
    /**
27
     * @var AbstractPaginationQuery
28
     */
29
    private AbstractPaginationQuery $filter;
30
31
    private array $params;
32
33
    /**
34
     * @param QueryBuilder $queryBuilder
35
     * @param AbstractPaginationQuery $filter
36
     * @param array $params
37
     */
38
    public function __construct(QueryBuilder $queryBuilder, AbstractPaginationQuery $filter, $params = array())
39
    {
40
        $this->queryBuilder = $queryBuilder;
41
        $this->filter = $filter;
42
        $this->params = $params;
43
    }
44
45
    public function getItems($offset, $itemCountPerPage)
46
    {
47
        try {
48
            $qb = $this->queryBuilder;
49
            $qb->skip($offset)->limit($itemCountPerPage);
50
            return $qb->getQuery()->toArray();
51
        }catch (\Exception $e){
52
            throw $e;
53
        }
54
    }
55
56
    /**
57
     * @return int
58
     * @throws \Doctrine\ODM\MongoDB\MongoDBException
59
     * FIXME: count method for ODM Module 3
60
     */
61
    public function count()
62
    {
63
        $qb = clone $this->queryBuilder;
64
        return $qb->count()->getQuery()->execute();
65
    }
66
67
}