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

Commit   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 40
ccs 5
cts 6
cp 0.8333
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
canCommit() 0 1 ?
A commit() 0 7 2
A isCommitted() 0 4 1
A allowChanges() 0 8 2
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