QueryWrapper::getRawSql()   A
last analyzed

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
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Smoren\QueryRelationManager\Yii2;
4
5
use Smoren\QueryRelationManager\Base\QueryWrapperInterface;
6
use yii\db\Connection;
7
use yii\db\Query;
8
9
/**
10
 * ActiveQuery wrapper implementation for QueryRelationManager
11
 * @author Smoren <[email protected]>
12
 * @inheritDoc
13
 */
14
class QueryWrapper implements QueryWrapperInterface
15
{
16
    /**
17
     * ActiveQuery instance
18
     * @var Query
19
     */
20
    protected Query $query;
21
22
    /**
23
     * QueryWrapper constructor
24
     */
25
    public function __construct()
26
    {
27
        $this->query = new Query();
28
    }
29
30
    /**
31
     * @inheritDoc
32
     */
33
    public function select(array $arSelect): QueryWrapperInterface
34
    {
35
        $this->query->select($arSelect);
36
37
        return $this;
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43
    public function from(array $mapFrom): QueryWrapperInterface
44
    {
45
        $this->query->from($mapFrom);
46
47
        return $this;
48
    }
49
50
    /**
51
     * @inheritDoc
52
     */
53
    public function join(
54
        string $type,
55
        array $mapTable,
56
        string $condition,
57
        array $extraJoinParams = []
58
    ): QueryWrapperInterface {
59
        $this->query->join("{$type} join", $mapTable, $condition, $extraJoinParams);
60
61
        return $this;
62
    }
63
64
    /**
65
     * @inheritDoc
66
     * @param Connection|null $db DB connection instance
67
     */
68
    public function all($db = null): array
69
    {
70
        return $this->query->all($db);
71
    }
72
73
    /**
74
     * @inheritDoc
75
     */
76
    public function getRawSql(): string
77
    {
78
        return $this->query->createCommand()->getRawSql();
79
    }
80
81
    /**
82
     * @inheritDoc
83
     * @return Query
84
     */
85
    public function getQuery(): Query
86
    {
87
        return $this->query;
88
    }
89
}
90