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

Commit   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 2
b 0
f 0
dl 0
loc 38
ccs 9
cts 10
cp 0.9
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A allowChanges() 0 7 2
A commit() 0 6 2
A isCommitted() 0 3 1
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