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

Xml   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 63
Duplicated Lines 31.75 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 20
loc 63
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A init() 20 20 2

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
3
namespace Loevgaard\AltaPay\Callback;
4
5
use Loevgaard\AltaPay\Entity\ResultTrait;
6
use Loevgaard\AltaPay\Entity\TransactionsTrait;
7
use Loevgaard\AltaPay\Exception\XmlException;
8
9
class Xml extends Callback
10
{
11
    use ResultTrait;
12
    use TransactionsTrait;
13
14
    /**
15
     * @var string
16
     */
17
    protected $xml;
18
19
    /**
20
     * Holds an XML object based on the Xml::$xml string
21
     *
22
     * @var \SimpleXMLElement
23
     */
24
    protected $xmlDoc;
25
26
    /**
27
     * @var string
28
     */
29
    protected $version;
30
31
    /**
32
     * @var \DateTimeImmutable
33
     */
34
    protected $date;
35
36
    /**
37
     * @var string
38
     */
39
    protected $path;
40
41
    /**
42
     * @var int
43
     */
44
    protected $errorCode;
45
46
    /**
47
     * @var string
48
     */
49
    protected $errorMessage;
50
51 View Code Duplication
    public function init()
0 ignored issues
show
Duplication introduced by
This method 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...
52
    {
53
        $this->xml = $this->body['xml'];
54
        $this->xmlDoc = new \SimpleXMLElement($this->xml);
55
        $this->version = (string)$this->xmlDoc['version'];
56
        $this->date = \DateTimeImmutable::createFromFormat(DATE_RFC3339, (string)$this->xmlDoc->Header->Date);
57
        if ($this->date === false) {
58
            $exception = new XmlException('The date format is wrong in xml header');
59
            $exception->setXmlElement($this->xmlDoc);
60
            throw $exception;
61
        }
62
        $this->path = (string)$this->xmlDoc->Header->Path;
63
        $this->errorCode = (int)$this->xmlDoc->Header->ErrorCode;
64
        $this->errorMessage = (string)$this->xmlDoc->Header->ErrorMessage;
65
66
        /** @var \SimpleXMLElement $body */
67
        $body = $this->xmlDoc->Body;
0 ignored issues
show
Bug introduced by
The property Body does not seem to exist in SimpleXMLElement.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
68
69
        $this->hydrateTransactions($body);
70
    }
71
}