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

Relation::getQuery()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
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\Criteria\Common\Field;
13
use RDS\Hydrogen\Query;
14
15
/**
16
 * Class Relation
17
 */
18 View Code Duplication
class Relation 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...
19
{
20
    /**
21
     * @var Field
22
     */
23
    private $relation;
24
25
    /**
26
     * @var \Closure|null
27
     */
28
    private $inner;
29
30
    /**
31
     * Relation constructor.
32
     * @param string $relation
33
     * @param Query $parent
34
     * @param \Closure|null $inner
35
     */
36
    public function __construct(Query $parent, string $relation, \Closure $inner = null)
37
    {
38
        parent::__construct($parent);
39
40
        $this->relation = $this->field($relation);
41
        $this->inner = $inner;
42
    }
43
44
    /**
45
     * @return Field
46
     */
47
    public function getRelation(): Field
48
    {
49
        return $this->relation;
50
    }
51
52
    /**
53
     * @return Query
54
     */
55
    public function getRelatedQuery(): Query
56
    {
57
        $related = $this->query->create();
58
59
        if ($this->inner) {
60
            ($this->inner)($related);
61
        }
62
63
        return $related;
64
    }
65
}
66