Slice   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A modify() 0 8 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