Completed
Push — master ( f632bc...c5ea05 )
by Andreas
03:40
created

Commit::commit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2.032
1
<?php
2
3
namespace Larium\Pay\Transaction;
4
5
use Larium\Pay\TransactionException;
6
7
trait Commit
8
{
9
    /**
10
     * @var bool
11
     */
12
    private $committed = false;
13
14
    abstract public function canCommit();
15
16
    /**
17
     * {@inheritdoc}
18
     */
19 7
    public function commit()
20
    {
21 7
        if (!$this->canCommit()) {
22
            throw TransactionException::unableToCommit();
23
        }
24 7
        $this->committed = true;
25 7
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 2
    public function isCommitted()
31
    {
32 2
        return $this->committed;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 2
    public function allowChanges()
39
    {
40 2
        if ($this->isCommitted()) {
41 1
            throw TransactionException::alreadyCommited();
42
        }
43
44 2
        return true;
45
    }
46
}
47