Passed
Pull Request — master (#617)
by Dmitriy
27:11 queued 24:49
created

TransactionInterfaceDecorator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Debug;
6
7
use Psr\Log\LoggerInterface;
8
use Yiisoft\Db\Transaction\TransactionInterface;
9
10
final class TransactionInterfaceDecorator implements TransactionInterface
11
{
12
    public function __construct(
13
        private TransactionInterface $decorated,
14
        private DatabaseCollector $collector
15
    ) {
16
    }
17
18
    public function setLogger(LoggerInterface $logger): void
19
    {
20
        $this->decorated->{__FUNCTION__}(...func_get_args());
21
    }
22
23
    public function begin(string $isolationLevel = null): void
24
    {
25
        [$callStack] = debug_backtrace();
26
27
        $this->collector->collectTransactionStart($isolationLevel, $callStack['file'] . ':' . $callStack['line']);
28
29
        $this->decorated->begin($isolationLevel);
30
    }
31
32
    public function commit(): void
33
    {
34
        [$callStack] = debug_backtrace();
35
36
        $this->decorated->commit();
37
38
        $this->collector->collectTransactionCommit($callStack['file'] . ':' . $callStack['line']);
39
    }
40
41
    public function getLevel(): int
42
    {
43
        return $this->decorated->getLevel();
44
    }
45
46
    public function isActive(): bool
47
    {
48
        return $this->decorated->isActive();
49
    }
50
51
    public function rollBack(): void
52
    {
53
        [$callStack] = debug_backtrace();
54
55
        $this->decorated->rollBack();
56
57
        $this->collector->collectTransactionRollback($callStack['file'] . ':' . $callStack['line']);
58
    }
59
60
    public function setIsolationLevel(string $level): void
61
    {
62
        $this->decorated->{__FUNCTION__}(...func_get_args());
63
    }
64
65
    public function createSavepoint(string $name): void
66
    {
67
        $this->decorated->{__FUNCTION__}(...func_get_args());
68
    }
69
70
    public function rollBackSavepoint(string $name): void
71
    {
72
        $this->decorated->{__FUNCTION__}(...func_get_args());
73
    }
74
75
    public function releaseSavepoint(string $name): void
76
    {
77
        $this->decorated->{__FUNCTION__}(...func_get_args());
78
    }
79
}
80