NativeQueryPagable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getTotal() 0 4 1
A setRange() 0 4 1
1
<?php
2
/**
3
 * @author Gerard van Helden <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
namespace Zicht\Bundle\FrameworkExtraBundle\Doctrine;
7
8
use Pdo;
9
use Zicht\Bundle\FrameworkExtraBundle\Pager\Pageable;
10
use Doctrine\ORM\NativeQuery;
11
use Doctrine\DBAL\Statement;
12
13
/**
14
 * Class NativeQueryPagable
15
 *
16
 * @package Zicht\Bundle\FrameworkExtraBundle\Doctrine
17
 */
18
class NativeQueryPagable implements Pageable
19
{
20
    /**
21
     * NativeQueryPagable constructor.
22
     *
23
     * @param NativeQuery $queryWrapper
24
     * @param Statement $countQuery
25
     */
26
    public function __construct(NativeQuery $queryWrapper, Statement $countQuery)
27
    {
28
        $this->query = $queryWrapper;
0 ignored issues
show
Bug Best Practice introduced by
The property query does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
29
        $this->countQuery = $countQuery;
0 ignored issues
show
Bug Best Practice introduced by
The property countQuery does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30
    }
31
32
    /**
33
     * @{inheritDoc}
34
     */
35
    public function getTotal()
36
    {
37
        $this->countQuery->execute();
38
        return $this->countQuery->fetch(Pdo::FETCH_COLUMN);
39
    }
40
41
    /**
42
     * @{inheritDoc}
43
     */
44
    public function setRange($start, $length)
45
    {
46
        $this->query->setParameter(':limit', (int)$length, Pdo::PARAM_INT);
47
        $this->query->setParameter(':offset', (int)$start, Pdo::PARAM_INT);
48
    }
49
}
50