Passed
Pull Request — master (#160)
by Dmitriy
02:28
created

TransactionInterfaceProxy   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 21
dl 0
loc 78
rs 10
c 1
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A setIsolationLevel() 0 3 1
A getLevel() 0 3 1
A isActive() 0 3 1
A createSavepoint() 0 3 1
A rollBack() 0 7 1
A beginTransaction() 0 8 1
A releaseSavepoint() 0 3 1
A commit() 0 7 1
A begin() 0 7 1
A setLogger() 0 3 1
A rollBackSavepoint() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector\Database;
6
7
use Psr\Log\LoggerInterface;
8
use Yiisoft\Db\Transaction\TransactionInterface;
9
10
final class TransactionInterfaceProxy implements TransactionInterface
11
{
12
    public function __construct(
13
        private TransactionInterface $decorated,
14
        private DatabaseCollector $collector
15
    ) {
16
    }
17
18
    public function beginTransaction(string $isolationLevel = null): TransactionInterface
19
    {
20
        [$callStack] = debug_backtrace();
21
22
        $result = $this->decorated->beginTransaction($isolationLevel);
0 ignored issues
show
Bug introduced by
The method beginTransaction() does not exist on Yiisoft\Db\Transaction\TransactionInterface. It seems like you code against a sub-type of Yiisoft\Db\Transaction\TransactionInterface such as Yiisoft\Yii\Debug\Collec...ansactionInterfaceProxy. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        /** @scrutinizer ignore-call */ 
23
        $result = $this->decorated->beginTransaction($isolationLevel);
Loading history...
23
24
        $this->collector->collectTransactionStart($isolationLevel, $callStack['file'] . ':' . $callStack['line']);
25
        return $result;
26
    }
27
28
    public function setLogger(LoggerInterface $logger): void
29
    {
30
        $this->decorated->{__FUNCTION__}(...func_get_args());
31
    }
32
33
    public function begin(string $isolationLevel = null): void
34
    {
35
        [$callStack] = debug_backtrace();
36
37
        $this->collector->collectTransactionStart($isolationLevel, $callStack['file'] . ':' . $callStack['line']);
38
39
        $this->decorated->begin($isolationLevel);
40
    }
41
42
    public function commit(): void
43
    {
44
        [$callStack] = debug_backtrace();
45
46
        $this->decorated->commit();
47
48
        $this->collector->collectTransactionCommit($callStack['file'] . ':' . $callStack['line']);
49
    }
50
51
    public function getLevel(): int
52
    {
53
        return $this->decorated->getLevel();
54
    }
55
56
    public function isActive(): bool
57
    {
58
        return $this->decorated->isActive();
59
    }
60
61
    public function rollBack(): void
62
    {
63
        [$callStack] = debug_backtrace();
64
65
        $this->decorated->rollBack();
66
67
        $this->collector->collectTransactionRollback($callStack['file'] . ':' . $callStack['line']);
68
    }
69
70
    public function setIsolationLevel(string $level): void
71
    {
72
        $this->decorated->{__FUNCTION__}(...func_get_args());
73
    }
74
75
    public function createSavepoint(string $name): void
76
    {
77
        $this->decorated->{__FUNCTION__}(...func_get_args());
78
    }
79
80
    public function rollBackSavepoint(string $name): void
81
    {
82
        $this->decorated->{__FUNCTION__}(...func_get_args());
83
    }
84
85
    public function releaseSavepoint(string $name): void
86
    {
87
        $this->decorated->{__FUNCTION__}(...func_get_args());
88
    }
89
}
90