Completed
Push — master ( 234de9...b59dba )
by Massimiliano
02:25
created

XmlLoadException   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 12.96 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 0
cbo 1
dl 7
loc 54
ccs 0
cts 37
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A __toString() 7 7 1
B decodeXmlError() 0 28 5

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 declare(strict_types=1);
2
3
namespace Fazland\SkebbyRestClient\Exception;
4
5
class XmlLoadException extends Exception
6
{
7
    /**
8
     * @var string
9
     */
10
    private $response;
11
12
    public function __construct($response, array $errors)
13
    {
14
        $this->response = $response;
15
        $this->message = '';
16
17
        foreach ($errors as $error) {
18
            $this->message .= $this->decodeXmlError($error, $response);
19
        }
20
    }
21
22 View Code Duplication
    public function __toString()
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...
23
    {
24
        return '[' . get_class($this) . '] ' . $this->message . "\n" .
25
            'Response: ' . "\n" .
26
            $this->response
27
        ;
28
    }
29
30
    private function decodeXmlError(\LibXMLError $error, $xml)
31
    {
32
        $return = $xml[$error->line - 1] . "\n";
33
34
        switch ($error->level) {
35
            case LIBXML_ERR_WARNING:
36
                $return .= "Warning $error->code: ";
37
                break;
38
39
            case LIBXML_ERR_ERROR:
40
                $return .= "Error $error->code: ";
41
                break;
42
43
            case LIBXML_ERR_FATAL:
44
                $return .= "Fatal Error $error->code: ";
45
                break;
46
        }
47
48
        $return .= trim($error->message) .
49
            "\n  Line: $error->line" .
50
            "\n  Column: $error->column";
51
52
        if ($error->file) {
53
            $return .= "\n  File: $error->file";
54
        }
55
56
        return $return . "\n\n";
57
    }
58
}
59