TransactionsTrait::hydrateTransactions()   B
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 5

Importance

Changes 0
Metric Value
dl 14
loc 14
ccs 9
cts 9
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 8
nc 3
nop 1
crap 5
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