Passed
Pull Request — 2.x (#225)
by Aleksei
18:04
created

SubQuery::getTokens()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of Cycle ORM package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Cycle\Database\Injection;
13
14
use Cycle\Database\Driver\CompilerInterface;
15
use Cycle\Database\Query\Interpolator;
16
use Cycle\Database\Query\QueryParameters;
17
use Cycle\Database\Query\SelectQuery;
18
19
class SubQuery implements FragmentInterface
20
{
21
    private SelectQuery $query;
22
    private string $alias;
23
24
    public function __construct(SelectQuery $query, string $alias)
25
    {
26
        $this->query = $query;
27
        $this->alias = $alias;
28
    }
29
30
    public function getType(): int
31
    {
32
        return CompilerInterface::SUBQUERY;
33
    }
34
35
    public function getTokens(): array
36
    {
37
        return \array_merge(['alias' => $this->alias], $this->query->getTokens());
38
    }
39
40
    public function getQuery(): SelectQuery
41
    {
42
        return $this->query;
43
    }
44
45
    public function __toString(): string
46
    {
47
        $parameters = new QueryParameters();
48
49
        return Interpolator::interpolate(
50
            $this->query->sqlStatement($parameters),
51
            $parameters->getParameters(),
52
        );
53
    }
54
}
55