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

Relation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 56
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getAlias() 0 4 1
A getRelation() 0 4 1
A getQuery() 0 10 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