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

WhereGroup::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 7
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
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