Completed
Push — master ( 425c1b...dc66d0 )
by Kirill
08:02
created

Criterion::isAttachedTo()   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 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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 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 61
    public function __construct(Query $query)
30
    {
31 61
        $this->query = $query;
32 61
    }
33
34
    /**
35
     * @param string $name
36
     * @return Field
37
     */
38 61
    protected function field(string $name): Field
39
    {
40 61
        return new Field($name);
41
    }
42
43
    /**
44
     * @param Query $query
45
     * @return CriterionInterface
46
     */
47
    public function attach(Query $query): CriterionInterface
48
    {
49
        $this->query = $query;
50
51
        return $this;
52
    }
53
54
    /**
55
     * @param Query $query
56
     * @return bool
57
     */
58
    public function isAttachedTo(Query $query): bool
59
    {
60
        return $this->query === $query;
61
    }
62
63
    /**
64
     * @return bool
65
     */
66 61
    public function isAttached(): bool
67
    {
68 61
        return $this->query !== null;
69
    }
70
71
    /**
72
     * @return Query
73
     */
74
    public function getQuery(): Query
75
    {
76
        return $this->query;
77
    }
78
79
    /**
80
     * @return string
81
     */
82 26
    public function getQueryAlias(): string
83
    {
84 26
        return $this->query->getAlias();
85
    }
86
}
87