TerminalsTrait::addTerminal()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 6
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Loevgaard\AltaPay\Entity;
4
5 View Code Duplication
trait TerminalsTrait
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 Terminal[]
9
     */
10
    protected $terminals;
11
12
    /**
13
     * @return Terminal[]
14
     */
15 15
    public function getTerminals(): array
16
    {
17 15
        $this->initializeTerminals();
18
19 15
        return $this->terminals;
20
    }
21
22
    /**
23
     * @param array $terminals
24
     */
25 3
    public function setTerminals(array $terminals)
26
    {
27 3
        $this->terminals = $terminals;
28 3
    }
29
30
    /**
31
     * @param Terminal $terminal
32
     */
33 3
    public function addTerminal(Terminal $terminal)
34
    {
35 3
        $this->initializeTerminals();
36
37 3
        $this->terminals[] = $terminal;
38 3
    }
39
40 9
    public function hydrateTerminals(\SimpleXMLElement $xml)
41
    {
42 9
        if (!isset($xml->Terminals) || !isset($xml->Terminals->Terminal) || empty($xml->Terminals->Terminal)) {
43 3
            return;
44
        }
45
46 6
        $this->initializeTerminals();
47
48 6
        foreach ($xml->Terminals->Terminal as $terminalXml) {
49 6
            $terminal = new Terminal();
50 6
            $terminal->hydrateXml($terminalXml);
51 6
            $this->terminals[] = $terminal;
52
        }
53 6
    }
54
55 15
    private function initializeTerminals()
56
    {
57 15
        if (is_null($this->terminals)) {
58 12
            $this->terminals = [];
59
        }
60 15
    }
61
}
62