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

Join   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 82.35%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 75
ccs 14
cts 17
cp 0.8235
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getType() 0 4 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 Join
17
 */
18
class Join extends Criterion
19
{
20
    public const TYPE_JOIN = 0x01;
21
    public const TYPE_INNER_JOIN = 0x02;
22
    public const TYPE_LEFT_JOIN = 0x03;
23
24
    /**
25
     * @var \Closure
26
     */
27
    private $inner;
28
29
    /**
30
     * @var Query
31
     */
32
    private $parent;
33
34
    /**
35
     * @var int
36
     */
37
    private $type;
38
39
    /**
40
     * Relation constructor.
41
     * @param string $relation
42
     * @param Query $parent
43
     * @param int $type
44
     * @param \Closure|null $inner
45
     */
46 2
    public function __construct(string $relation, Query $parent, int $type = self::TYPE_JOIN, \Closure $inner = null)
47
    {
48 2
        parent::__construct($relation);
49
50 2
        $this->type = $type;
51 2
        $this->inner = $inner;
52 2
        $this->parent = $parent;
53 2
    }
54
55
    /**
56
     * @return int
57
     */
58 2
    public function getType(): int
59
    {
60 2
        return $this->type;
61
    }
62
63
    /**
64
     * @return string
65
     */
66 2
    public function getAlias(): string
67
    {
68 2
        return $this->parent->getAlias();
69
    }
70
71
    /**
72
     * @return Field
73
     */
74
    public function getRelation(): Field
75
    {
76
        return $this->getField();
77
    }
78
79
    /**
80
     * @return Query
81
     */
82 2
    public function getQuery(): Query
83
    {
84 2
        $query = $this->parent->create();
85
86 2
        if ($this->inner) {
87
            ($this->inner)($query);
88
        }
89
90 2
        return $query;
91
    }
92
}
93