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

ReconciliationIdentifier::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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