TransactionsTrait   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 57
loc 57
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeTransactions() 6 6 2
A getTransactions() 6 6 1
A setTransactions() 4 4 1
A addTerminal() 6 6 1
B hydrateTransactions() 14 14 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Loevgaard\AltaPay\Entity;
4
5 View Code Duplication
trait TransactionsTrait
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6
{
7
    /**
8
     * @var Transaction[]
9
     */
10
    protected $transactions;
11
12
    /**
13
     * @return Transaction[]
14
     */
15 12
    public function getTransactions(): array
16
    {
17 12
        $this->initializeTransactions();
18
19 12
        return $this->transactions;
20
    }
21
22
    /**
23
     * @param array $transactions
24
     */
25 3
    public function setTransactions(array $transactions)
26
    {
27 3
        $this->transactions = $transactions;
28 3
    }
29
30
    /**
31
     * @param Transaction $transaction
32
     */
33 3
    public function addTerminal(Transaction $transaction)
34
    {
35 3
        $this->initializeTransactions();
36
37 3
        $this->transactions[] = $transaction;
38 3
    }
39
40 24
    public function hydrateTransactions(\SimpleXMLElement $xml)
41
    {
42 24
        if (!isset($xml->Transactions) || !isset($xml->Transactions->Transaction) || empty($xml->Transactions->Transaction)) {
43 9
            return;
44
        }
45
46 15
        $this->initializeTransactions();
47
48 15
        foreach ($xml->Transactions->Transaction as $transactionXml) {
49 15
            $transaction = new Transaction();
50 15
            $transaction->hydrateXml($transactionXml);
51 15
            $this->transactions[] = $transaction;
52
        }
53 15
    }
54
55 24
    private function initializeTransactions()
56
    {
57 24
        if (is_null($this->transactions)) {
58 15
            $this->transactions = [];
59
        }
60 24
    }
61
}
62