Completed
Push — master ( 60aec0...f632bc )
by Andreas
12:47 queued 10:41
created

Commit::commit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2.0625
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
        if (!$this->canCommit()) {
22
            throw TransactionException::unableToCommit();
23
        }
24 7
        $this->committed = true;
25 7
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function isCommitted()
31
    {
32
        return $this->committed;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function allowChanges()
39
    {
40
        if ($this->isCommitted()) {
41
            throw TransactionException::alreadyCommited();
42
        }
43
44 1
        return true;
45
    }
46
}
47