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

TransactionInterfaceDecorator   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 72
rs 10
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A isActive() 0 3 1
A commit() 0 7 1
A getLevel() 0 3 1
A setIsolationLevel() 0 3 1
A createSavepoint() 0 3 1
A begin() 0 7 1
A rollBack() 0 7 1
A rollBackSavepoint() 0 3 1
A __construct() 0 4 1
A releaseSavepoint() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Debug;
6
7
use Yiisoft\Db\Transaction\TransactionInterface;
8
9
final class TransactionInterfaceDecorator implements TransactionInterface
10
{
11
    public function __construct(
12
        private TransactionInterface $decorated,
13
        private DatabaseCollector $collector
14
    ) {
15
    }
16
17
    /**
18
     * @psalm-suppress PossiblyUndefinedArrayOffset
19
     */
20
    public function begin(string $isolationLevel = null): void
21
    {
22
        [$callStack] = debug_backtrace();
23
24
        $this->collector->collectTransactionStart($isolationLevel, $callStack['file'] . ':' . $callStack['line']);
25
26
        $this->decorated->begin($isolationLevel);
27
    }
28
29
    /**
30
     * @psalm-suppress PossiblyUndefinedArrayOffset
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
    /**
52
     * @psalm-suppress PossiblyUndefinedArrayOffset
53
     */
54
    public function rollBack(): void
55
    {
56
        [$callStack] = debug_backtrace();
57
58
        $this->decorated->rollBack();
59
60
        $this->collector->collectTransactionRollback($callStack['file'] . ':' . $callStack['line']);
61
    }
62
63
    public function setIsolationLevel(string $level): void
64
    {
65
        $this->decorated->{__FUNCTION__}(...func_get_args());
66
    }
67
68
    public function createSavepoint(string $name): void
69
    {
70
        $this->decorated->{__FUNCTION__}(...func_get_args());
71
    }
72
73
    public function rollBackSavepoint(string $name): void
74
    {
75
        $this->decorated->{__FUNCTION__}(...func_get_args());
76
    }
77
78
    public function releaseSavepoint(string $name): void
79
    {
80
        $this->decorated->{__FUNCTION__}(...func_get_args());
81
    }
82
}
83