Xml   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 70
Duplicated Lines 28.57 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 20
loc 70
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 20 20 2
A initable() 0 6 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
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
use Psr\Http\Message\ServerRequestInterface;
9
10
class Xml extends Callback
11
{
12
    use ResultTrait;
13
    use TransactionsTrait;
14
15
    /**
16
     * @var string
17
     */
18
    protected $xml;
19
20
    /**
21
     * Holds an XML object based on the Xml::$xml string
22
     *
23
     * @var \SimpleXMLElement
24
     */
25
    protected $xmlDoc;
26
27
    /**
28
     * @var string
29
     */
30
    protected $version;
31
32
    /**
33
     * @var \DateTimeImmutable
34
     */
35
    protected $date;
36
37
    /**
38
     * @var string
39
     */
40
    protected $path;
41
42
    /**
43
     * @var int
44
     */
45
    protected $errorCode;
46
47
    /**
48
     * @var string
49
     */
50
    protected $errorMessage;
51
52 9 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...
53
    {
54 9
        $this->xml = $this->body['xml'];
55 9
        $this->xmlDoc = new \SimpleXMLElement($this->xml);
56 9
        $this->version = (string)$this->xmlDoc['version'];
57 9
        $this->date = \DateTimeImmutable::createFromFormat(DATE_RFC3339, (string)$this->xmlDoc->Header->Date);
58 9
        if ($this->date === false) {
59 3
            $exception = new XmlException('The date format is wrong in xml header');
60 3
            $exception->setXmlElement($this->xmlDoc);
61 3
            throw $exception;
62
        }
63 6
        $this->path = (string)$this->xmlDoc->Header->Path;
64 6
        $this->errorCode = (int)$this->xmlDoc->Header->ErrorCode;
65 6
        $this->errorMessage = (string)$this->xmlDoc->Header->ErrorMessage;
66
67
        /** @var \SimpleXMLElement $body */
68 6
        $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...
69
70 6
        $this->hydrateTransactions($body);
71 6
    }
72
73 18
    public static function initable(ServerRequestInterface $request): bool
74
    {
75 18
        $body = static::getBodyFromRequest($request);
76
77 18
        return isset($body['xml']);
78
    }
79
}
80