CountOf::getFilter()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.9332
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\Specification;
15
16
use Doctrine\ORM\QueryBuilder;
17
use Happyr\DoctrineSpecification\Filter\Filter;
18
use Happyr\DoctrineSpecification\Query\QueryModifier;
19
20
/**
21
 * @author Tobias Nyholm
22
 */
23 View Code Duplication
class CountOf implements Specification
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
{
25
    /**
26
     * @var Filter|QueryModifier child
27
     */
28
    private $child;
29
30
    /**
31
     * @param Filter|QueryModifier $child
32
     */
33
    public function __construct($child)
34
    {
35
        $this->child = $child;
36
    }
37
38
    /**
39
     * @param QueryBuilder $qb
40
     * @param string       $dqlAlias
41
     *
42
     * @return string
43
     */
44
    public function getFilter(QueryBuilder $qb, $dqlAlias)
45
    {
46
        $qb->select(sprintf('COUNT(%s)', $dqlAlias));
47
48
        if ($this->child instanceof Filter) {
49
            return $this->child->getFilter($qb, $dqlAlias);
50
        }
51
52
        return '';
53
    }
54
55
    /**
56
     * @param QueryBuilder $qb
57
     * @param string       $dqlAlias
58
     */
59
    public function modify(QueryBuilder $qb, $dqlAlias)
60
    {
61
        if ($this->child instanceof QueryModifier) {
62
            $this->child->modify($qb, $dqlAlias);
63
        }
64
    }
65
}
66