Completed
Push — master ( ad55a4...c98fe8 )
by Joachim
01:57
created

ReconciliationIdentifier::hydrateXml()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 5
Ratio 35.71 %

Code Coverage

Tests 8
CRAP Score 2.0811

Importance

Changes 0
Metric Value
dl 5
loc 14
ccs 8
cts 11
cp 0.7272
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 1
crap 2.0811
1
<?php
2
namespace Loevgaard\AltaPay\Entity;
3
4
use Loevgaard\AltaPay\Exception\XmlException;
5
use Loevgaard\AltaPay\Hydrator\HydratableInterface;
6
7
class ReconciliationIdentifier implements HydratableInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private $id;
13
14
    /**
15
     * @var float
16
     */
17
    private $amount;
18
19
    /**
20
     * @var int
21
     */
22
    private $amountCurrency;
23
24
    /**
25
     * @var string
26
     */
27
    private $type;
28
29
    /**
30
     * @var \DateTimeImmutable
31
     */
32
    private $date;
33
34 9
    public function hydrateXml(\SimpleXMLElement $xml)
35
    {
36 9
        $this->id = (string)$xml->Id;
37 9
        $this->amount = (float)$xml->Amount;
38 9
        $this->amountCurrency = (int)$xml->Amount['currency'];
39 9
        $this->type = (string)$xml->Type;
40
41 9
        $this->date = \DateTimeImmutable::createFromFormat(DATE_RFC3339, (string)$xml->Date);
42 9 View Code Duplication
        if ($this->date === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
43
            $exception = new XmlException('The date format is wrong');
44
            $exception->setXmlElement($xml);
45
            throw $exception;
46
        }
47 9
    }
48
49
    /**
50
     * @return string
51
     */
52 3
    public function getId() : string
53
    {
54 3
        return $this->id;
55
    }
56
57
    /**
58
     * @return float
59
     */
60 3
    public function getAmount() : float
61
    {
62 3
        return $this->amount;
63
    }
64
65
    /**
66
     * @return int
67
     */
68 3
    public function getAmountCurrency() : int
69
    {
70 3
        return $this->amountCurrency;
71
    }
72
73
    /**
74
     * @return string
75
     */
76 3
    public function getType() : string
77
    {
78 3
        return $this->type;
79
    }
80
81
    /**
82
     * @return \DateTimeImmutable
83
     */
84 3
    public function getDate(): \DateTimeImmutable
85
    {
86 3
        return $this->date;
87
    }
88
}
89