Having   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A modify() 12 12 3
A getFilter() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
@trigger_error('The '.__NAMESPACE__.'\Having class is deprecated since version 1.1 and will be removed in 2.0, use \Happyr\DoctrineSpecification\Query\Having instead.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
21
22
/**
23
 * @deprecated This class is deprecated since version 1.1 and will be removed in 2.0, use \Happyr\DoctrineSpecification\Query\Having instead.
24
 */
25 View Code Duplication
class Having 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...
26
{
27
    /**
28
     * @var Filter|QueryModifier|string
29
     */
30
    protected $child;
31
32
    /**
33
     * @param Filter|QueryModifier|string $child
34
     */
35
    public function __construct($child)
36
    {
37
        $this->child = $child;
38
    }
39
40
    /**
41
     * @param QueryBuilder $qb
42
     * @param string       $dqlAlias
43
     */
44
    public function modify(QueryBuilder $qb, $dqlAlias)
45
    {
46
        if ($this->child instanceof QueryModifier) {
47
            $this->child->modify($qb, $dqlAlias);
48
        }
49
50
        if ($this->child instanceof Filter) {
51
            $qb->having($this->child->getFilter($qb, $dqlAlias));
52
        } else {
53
            $qb->having($this->child);
54
        }
55
    }
56
57
    /**
58
     * @param QueryBuilder $qb
59
     * @param string       $dqlAlias
60
     *
61
     * @return string
62
     */
63
    public function getFilter(QueryBuilder $qb, $dqlAlias)
64
    {
65
        return '';
66
    }
67
}
68