Passed
Pull Request — master (#2)
by Andreas
11:41
created

Commit::allowChanges()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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