ReconciliationIdentifier::hydrateXml()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

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