| Total Complexity | 7 |
| Total Lines | 61 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | trait HandlesDatabaseTransactions |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Determines whether class uses transaction. |
||
| 13 | * |
||
| 14 | * @var bool |
||
| 15 | */ |
||
| 16 | protected bool $useTransaction = false; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Enable transaction in pipeline. |
||
| 20 | * |
||
| 21 | * @return static |
||
| 22 | */ |
||
| 23 | 2 | public function withTransaction(): static |
|
| 24 | { |
||
| 25 | 2 | $this->useTransaction = true; |
|
| 26 | |||
| 27 | 2 | return $this; |
|
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Begin the transaction if enabled. |
||
| 32 | * |
||
| 33 | * @return void |
||
| 34 | */ |
||
| 35 | 20 | protected function beginTransaction(): void |
|
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Commit the transaction if enabled. |
||
| 46 | * |
||
| 47 | * @return void |
||
| 48 | */ |
||
| 49 | 12 | protected function commitTransaction(): void |
|
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Rollback the transaction if enabled. |
||
| 60 | * |
||
| 61 | * @return void |
||
| 62 | */ |
||
| 63 | 4 | protected function rollbackTransaction(): void |
|
| 72 |