DatabaseTransactionTrait::useTransaction()   A
last analyzed

Complexity

Conditions 3
Paths 5

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.4609

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 14
ccs 5
cts 11
cp 0.4545
rs 9.9
c 0
b 0
f 0
cc 3
nc 5
nop 1
crap 4.4609
1
<?php
2
declare(strict_types=1);
3
4
namespace Xervice\Database\Business\Transaction;
5
6
7
use Propel\Runtime\Propel;
8
9
trait DatabaseTransactionTrait
10
{
11
    /**
12
     * @param callable $callable
13
     *
14
     * @throws \Throwable
15
     */
16 1
    public function useTransaction(callable $callable)
17
    {
18 1
        $connection = Propel::getConnection();
19 1
        $connection->beginTransaction();
20
21
        try {
22 1
            $callable();
23 1
            $connection->commit();
24
        } catch (\Exception $exception) {
25
            $connection->rollBack();
26
            throw $exception;
27
        } catch (\Throwable $throwable) {
28
            $connection->rollBack();
29
            throw $throwable;
30
        }
31
    }
32
}