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

Transaction::commit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 10
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 Transaction
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
        if (!self::getConnection()) {
46
            throw DatabaseException::missingConfig();
47
        }
48
49
        (self::$ormClass)::get_db()->commit();
50
    }
51
52
    /**
53
     * Rolls back a transaction
54
     * @throws DatabaseException
55
     */
56
    public static function rollback(): void
57
    {
58
        if (!self::getConnection()) {
59
            throw DatabaseException::missingConfig();
60
        }
61
62
        (self::$ormClass)::get_db()->rollBack();
63
    }
64
}