Slice::modify()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
/**
4
 * This file is part of the Happyr Doctrine Specification package.
5
 *
6
 * (c) Tobias Nyholm <[email protected]>
7
 *     Kacper Gunia <[email protected]>
8
 *     Peter Gribanov <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Happyr\DoctrineSpecification\Query;
15
16
use Doctrine\ORM\QueryBuilder;
17
18
class Slice implements QueryModifier
19
{
20
    /**
21
     * @var int
22
     */
23
    private $sliceSize;
24
25
    /**
26
     * @var int
27
     */
28
    private $sliceNumber = 0;
29
30
    /**
31
     * @param int $sliceSize
32
     * @param int $sliceNumber
33
     */
34
    public function __construct($sliceSize, $sliceNumber = 0)
35
    {
36
        $this->sliceSize = $sliceSize;
37
        $this->sliceNumber = $sliceNumber;
38
    }
39
40
    /**
41
     * @param QueryBuilder $qb
42
     * @param string       $dqlAlias
43
     */
44
    public function modify(QueryBuilder $qb, $dqlAlias)
45
    {
46
        $qb->setMaxResults($this->sliceSize);
47
48
        if ($this->sliceNumber > 0) {
49
            $qb->setFirstResult($this->sliceNumber * $this->sliceSize);
50
        }
51
    }
52
}
53