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

ReconciliationIdentifier   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 6.1 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 5
loc 82
ccs 18
cts 21
cp 0.8571
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A hydrateXml() 5 14 2
A getId() 0 4 1
A getAmount() 0 4 1
A getAmountCurrency() 0 4 1
A getType() 0 4 1
A getDate() 0 4 1

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
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