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

Criterion   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 60
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A field() 0 4 1
A attach() 0 6 1
A isAttached() 0 4 1
A getQuery() 0 4 1
A getQueryAlias() 0 4 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\Criteria\Common\Field;
13
use RDS\Hydrogen\Query;
14
15
/**
16
 * Class Criterion
17
 */
18
abstract class Criterion implements CriterionInterface
19
{
20
    /**
21
     * @var Query
22
     */
23
    protected $query;
24
25
    /**
26
     * Criterion constructor.
27
     * @param Query $query
28
     */
29 65
    public function __construct(Query $query)
30
    {
31 65
        $this->query = $query;
32 65
    }
33
34
    /**
35
     * @param string $name
36
     * @return Field
37
     */
38 65
    protected function field(string $name): Field
39
    {
40 65
        return new Field($name);
41
    }
42
43
    /**
44
     * @param Query $query
45
     * @return CriterionInterface
46
     */
47 4
    public function attach(Query $query): CriterionInterface
48
    {
49 4
        $this->query = $query;
50
51 4
        return $this;
52
    }
53
54
    /**
55
     * @return bool
56
     */
57 65
    public function isAttached(): bool
58
    {
59 65
        return $this->query !== null;
60
    }
61
62
    /**
63
     * @return Query
64
     */
65
    public function getQuery(): Query
66
    {
67
        return $this->query;
68
    }
69
70
    /**
71
     * @return string
72
     */
73 30
    public function getQueryAlias(): string
74
    {
75 30
        return $this->query->getAlias();
76
    }
77
}
78