Passed
Push — master ( c80e12...1c5165 )
by Kirill
04:32
created

Relation::getAlias()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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
class Relation extends Criterion
19
{
20
    /**
21
     * @var \Closure
22
     */
23
    private $inner;
24
25
    /**
26
     * @var Query
27
     */
28
    private $parent;
29
30
    /**
31
     * Relation constructor.
32
     * @param string $relation
33
     * @param Query $parent
34
     * @param \Closure|null $inner
35
     */
36
    public function __construct(string $relation, Query $parent, \Closure $inner = null)
37
    {
38
        parent::__construct($relation);
39
40
        $this->inner = $inner;
41
        $this->parent = $parent;
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getAlias(): string
48
    {
49
        return $this->parent->getAlias();
50
    }
51
52
    /**
53
     * @return Field
54
     */
55
    public function getRelation(): Field
56
    {
57
        return $this->getField();
58
    }
59
60
    /**
61
     * @return Query
62
     */
63
    public function getQuery(): Query
64
    {
65
        $query = $this->parent->create();
66
67
        if ($this->inner) {
68
            ($this->inner)($query);
69
        }
70
71
        return $query;
72
    }
73
}
74