Completed
Push — master ( 52a6e0...c01d36 )
by Dmitriy
51s queued 49s
created

ConnectionInterfaceProxy::getSchema()   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
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Debug;
6
7
use Closure;
8
use Yiisoft\Db\Command\CommandInterface;
9
use Yiisoft\Db\Connection\ConnectionInterface;
10
use Yiisoft\Db\Query\BatchQueryResultInterface;
11
use Yiisoft\Db\Query\QueryInterface;
12
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
13
use Yiisoft\Db\Schema\QuoterInterface;
14
use Yiisoft\Db\Schema\SchemaInterface;
15
use Yiisoft\Db\Schema\TableSchemaInterface;
16
use Yiisoft\Db\Transaction\TransactionInterface;
17
18
final class ConnectionInterfaceProxy implements ConnectionInterface
19
{
20
    public function __construct(
21
        private ConnectionInterface $connection,
22
        private DatabaseCollector $collector
23
    ) {
24
    }
25
26
    /**
27
     * @psalm-suppress PossiblyUndefinedArrayOffset
28
     */
29
    public function beginTransaction(string $isolationLevel = null): TransactionInterface
30
    {
31
        [$callStack] = debug_backtrace();
32
33
        $result = $this->connection->beginTransaction($isolationLevel);
34
35
        $this->collector->collectTransactionStart($isolationLevel, $callStack['file'] . ':' . $callStack['line']);
36
        return new TransactionInterfaceDecorator($result, $this->collector);
37
    }
38
39
    public function createBatchQueryResult(QueryInterface $query, bool $each = false): BatchQueryResultInterface
40
    {
41
        return $this->connection->createBatchQueryResult($query, $each);
42
    }
43
44
    public function createCommand(string $sql = null, array $params = []): CommandInterface
45
    {
46
        return new CommandInterfaceProxy(
47
            $this->connection->createCommand($sql, $params),
48
            $this->collector,
49
        );
50
    }
51
52
    public function createTransaction(): TransactionInterface
53
    {
54
        return new TransactionInterfaceDecorator(
55
            $this->connection->createTransaction(),
56
            $this->collector,
57
        );
58
    }
59
60
    public function close(): void
61
    {
62
        $this->connection->close();
63
    }
64
65
    public function getLastInsertID(string $sequenceName = null): string
66
    {
67
        return $this->connection->getLastInsertID($sequenceName);
68
    }
69
70
    public function getQueryBuilder(): QueryBuilderInterface
71
    {
72
        return $this->connection->getQueryBuilder();
73
    }
74
75
    public function getQuoter(): QuoterInterface
76
    {
77
        return $this->connection->getQuoter();
78
    }
79
80
    public function getSchema(): SchemaInterface
81
    {
82
        return $this->connection->getSchema();
83
    }
84
85
    public function getServerVersion(): string
86
    {
87
        return $this->connection->getServerVersion();
88
    }
89
90
    public function getTablePrefix(): string
91
    {
92
        return $this->connection->getTablePrefix();
93
    }
94
95
    public function getTableSchema(string $name, bool $refresh = false): TableSchemaInterface|null
96
    {
97
        return $this->connection->getTableSchema($name, $refresh);
98
    }
99
100
    public function getTransaction(): TransactionInterface|null
101
    {
102
        $result = $this->connection->getTransaction();
103
104
        return $result === null
105
            ? null
106
            : new TransactionInterfaceDecorator(
107
                $result,
108
                $this->collector,
109
            );
110
    }
111
112
    public function isActive(): bool
113
    {
114
        return $this->connection->isActive();
115
    }
116
117
    public function isSavepointEnabled(): bool
118
    {
119
        return $this->connection->isSavepointEnabled();
120
    }
121
122
    public function open(): void
123
    {
124
        $this->connection->open();
125
    }
126
127
    public function quoteValue(mixed $value): mixed
128
    {
129
        return $this->connection->quoteValue($value);
130
    }
131
132
    public function setEnableSavepoint(bool $value): void
133
    {
134
        $this->connection->setEnableSavepoint($value);
135
    }
136
137
    public function setTablePrefix(string $value): void
138
    {
139
        $this->connection->setTablePrefix($value);
140
    }
141
142
    /**
143
     * @psalm-param Closure(self): mixed $closure
144
     * @psalm-suppress PossiblyUndefinedArrayOffset
145
     */
146
    public function transaction(Closure $closure, string $isolationLevel = null): mixed
147
    {
148
        [$callStack] = debug_backtrace();
149
150
        $this->collector->collectTransactionStart($isolationLevel, $callStack['file'] . ':' . $callStack['line']);
151
152
        return $this->connection->transaction(fn (): mixed => $closure($this), $isolationLevel);
153
    }
154
155
    public function getDriverName(): string
156
    {
157
        return $this->connection->getDriverName();
158
    }
159
}
160