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

Selection::getField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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 Selection
17
 */
18
class Selection extends Criterion
19
{
20
    /**
21
     * @var Field
22
     */
23
    private $field;
24
25
    /**
26
     * @var string|null
27
     */
28
    private $as;
29
30
    /**
31
     * Selection constructor.
32
     * @param Query $query
33
     * @param string $field
34
     * @param string|null $alias
35
     */
36 30
    public function __construct(Query $query, string $field, string $alias = null)
37
    {
38 30
        parent::__construct($query);
39
40 30
        $this->field = $this->field($field);
41 30
        $this->as = $alias;
42 30
    }
43
44
    /**
45
     * @return bool
46
     */
47 30
    public function hasAlias(): bool
48
    {
49 30
        return $this->as !== null;
50
    }
51
52
    /**
53
     * @return null|string
54
     */
55
    public function getAlias(): ?string
56
    {
57
        return $this->as;
58
    }
59
60
    /**
61
     * @return Field
62
     */
63 30
    public function getField(): Field
64
    {
65 30
        return $this->field;
66
    }
67
}
68