Total Complexity | 6 |
Total Lines | 49 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
17 | class Transaction { |
||
18 | |||
19 | use FactoryTrait; |
||
20 | |||
21 | /** |
||
22 | * @var bool |
||
23 | */ |
||
24 | protected $committed = false; |
||
25 | |||
26 | /** |
||
27 | * @var DB |
||
28 | */ |
||
29 | protected $db; |
||
30 | |||
31 | /** |
||
32 | * Begins the transaction/savepoint. |
||
33 | * |
||
34 | * @param DB $db |
||
35 | */ |
||
36 | public function __construct (DB $db) { |
||
37 | $this->db = $db; |
||
38 | $db->beginTransaction(); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Rolls back if the instance wasn't committed. |
||
43 | */ |
||
44 | public function __destruct () { |
||
45 | if (!$this->committed) { |
||
46 | $this->db->rollBack(); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Commits the transaction/savepoint. |
||
52 | * |
||
53 | * This is safe to call multiple times, it won't have any effect after the first time. |
||
54 | * |
||
55 | * @return true |
||
56 | */ |
||
57 | public function commit (): bool { |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @return bool |
||
63 | */ |
||
64 | final public function wasCommitted (): bool { |
||
66 | } |
||
67 | } |