ReconciliationIdentifiersTrait   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 58
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 58
loc 58
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getReconciliationIdentifiers() 6 6 1
A initializeReconciliationIdentifiers() 6 6 2
A setReconciliationIdentifiers() 4 4 1
A addReconciliationIdentifier() 6 6 1
B hydrateReconciliationIdentifiers() 15 15 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 ReconciliationIdentifiersTrait
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 ReconciliationIdentifier[]
9
     */
10
    protected $reconciliationIdentifiers;
11
12
    /**
13
     * @return ReconciliationIdentifier[]
14
     */
15 15
    public function getReconciliationIdentifiers(): array
16
    {
17 15
        $this->initializeReconciliationIdentifiers();
18
19 15
        return $this->reconciliationIdentifiers;
20
    }
21
22
    /**
23
     * @param array $reconciliationIdentifiers
24
     */
25 3
    public function setReconciliationIdentifiers(array $reconciliationIdentifiers)
26
    {
27 3
        $this->reconciliationIdentifiers = $reconciliationIdentifiers;
28 3
    }
29
30
    /**
31
     * @param ReconciliationIdentifier $reconciliationIdentifier
32
     */
33 3
    public function addReconciliationIdentifier(ReconciliationIdentifier $reconciliationIdentifier)
34
    {
35 3
        $this->initializeReconciliationIdentifiers();
36
37 3
        $this->reconciliationIdentifiers[] = $reconciliationIdentifier;
38 3
    }
39
40 33
    public function hydrateReconciliationIdentifiers(\SimpleXMLElement $xml)
41
    {
42 33
        if (!isset($xml->ReconciliationIdentifiers) || !isset($xml->ReconciliationIdentifiers->ReconciliationIdentifier)
43 33
            || empty($xml->ReconciliationIdentifiers->ReconciliationIdentifier)) {
44 12
            return;
45
        }
46
47 21
        $this->initializeReconciliationIdentifiers();
48
49 21
        foreach ($xml->ReconciliationIdentifiers->ReconciliationIdentifier as $reconciliationIdentifierXml) {
50 21
            $reconciliationIdentifier = new ReconciliationIdentifier();
51 21
            $reconciliationIdentifier->hydrateXml($reconciliationIdentifierXml);
52 21
            $this->reconciliationIdentifiers[] = $reconciliationIdentifier;
53
        }
54 21
    }
55
56 30
    private function initializeReconciliationIdentifiers()
57
    {
58 30
        if (is_null($this->reconciliationIdentifiers)) {
59 27
            $this->reconciliationIdentifiers = [];
60
        }
61 30
    }
62
}
63