Passed
Pull Request — master (#288)
by Arman
02:58
created

Transaction   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A beginTransaction() 0 7 2
A commit() 0 8 2
A rollback() 0 7 2
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.9.7
13
 */
14
15
namespace Quantum\Libraries\Database\Adapters\Idiorm\Statements;
16
17
use Quantum\Libraries\Database\Exceptions\DatabaseException;
18
19
/**
20
 * Trait Query
21
 * @package Quantum\Libraries\Database
22
 */
23
trait Transaction
24
{
25
26
    /**
27
     * Begins a transaction
28
     * @throws DatabaseException
29
     */
30
    public static function beginTransaction()
31
    {
32
        if (!self::getConnection()) {
33
            throw DatabaseException::missingConfig();
34
        }
35
36
        (self::$ormClass)::get_db()->beginTransaction();
37
    }
38
39
    /**
40
     * Commits a transaction
41
     * @throws DatabaseException
42
     */
43
    public static function commit(): void
44
    {
45
46
        if (!self::getConnection()) {
47
            throw DatabaseException::missingConfig();
48
        }
49
50
        (self::$ormClass)::get_db()->commit();
51
    }
52
53
    /**
54
     * Rolls back a transaction
55
     * @throws DatabaseException
56
     */
57
    public static function rollback(): void
58
    {
59
        if (!self::getConnection()) {
60
            throw DatabaseException::missingConfig();
61
        }
62
63
        (self::$ormClass)::get_db()->rollBack();
64
    }
65
}