Completed
Push — master ( b7ef6a...58a002 )
by Kirill
03:12
created

WhereGroup   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 47
loc 47
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A isAnd() 4 4 1
A getQuery() 9 9 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
 * This file is part of Hydrogen package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace RDS\Hydrogen\Criteria;
11
12
use RDS\Hydrogen\Query;
13
14
/**
15
 * Class WhereGroup
16
 */
17 View Code Duplication
class WhereGroup extends Criterion
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...
18
{
19
    /**
20
     * @var bool
21
     */
22
    private $conjunction;
23
24
    /**
25
     * @var \Closure
26
     */
27
    private $then;
28
29
    /**
30
     * Group constructor.
31
     * @param Query $parent
32
     * @param \Closure $then
33
     * @param bool $conjunction
34
     */
35 5
    public function __construct(Query $parent, \Closure $then, bool $conjunction = true)
36
    {
37 5
        parent::__construct($parent);
38
39 5
        $this->then = $then;
40 5
        $this->conjunction = $conjunction;
41 5
    }
42
43
    /**
44
     * @return bool
45
     */
46 5
    public function isAnd(): bool
47
    {
48 5
        return $this->conjunction;
49
    }
50
51
    /**
52
     * @return Query
53
     */
54 5
    public function getQuery(): Query
55
    {
56 5
        $query = $this->query->create()
57 5
            ->withAlias($this->query->getAlias());
58
59 5
        ($this->then)($query);
60
61 5
        return $query;
62
    }
63
}
64