Passed
Pull Request — 2.x (#225)
by
unknown
15:28
created

SubQueryInjection::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
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 SubQueryInjection 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
        return $this->query;
42
    }
43
44
    public function __toString(): string{
45
        $parameters = new QueryParameters();
46
47
        return Interpolator::interpolate(
48
            $this->query->sqlStatement($parameters),
49
            $parameters->getParameters(),
50
        );
51
    }
52
}
53