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

Criterion::withAlias()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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