Response   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 29.63 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 16
loc 54
ccs 13
cts 15
cp 0.8667
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isSuccess() 0 4 1
A getErrorCode() 8 8 2
A getErrorMessage() 8 8 2
A getResponse() 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 mikemix\Wiziq\API;
3
4
class Response
5
{
6
    /** @var \SimpleXMLElement */
7
    protected $xml;
8
9 3
    public function __construct(\SimpleXMLElement $xml)
10
    {
11 3
        $this->xml = $xml;
12 3
    }
13
14
    /**
15
     * Was this API call successful
16
     *
17
     * @return bool
18
     */
19 3
    public function isSuccess()
20
    {
21 3
        return (string)$this->xml['status'] !== 'fail';
22
    }
23
24
    /**
25
     * If not return error code
26
     */
27 2 View Code Duplication
    public function getErrorCode()
28
    {
29 2
        if ($this->isSuccess()) {
30
            throw new \BadMethodCallException('Response is correct, no error code available');
31
        }
32
33 2
        return (int)$this->xml->error[0]['code'];
34
    }
35
36
    /**
37
     * If not return error message
38
     */
39 2 View Code Duplication
    public function getErrorMessage()
40
    {
41 2
        if ($this->isSuccess()) {
42
            throw new \BadMethodCallException('Response is correct, no error message available');
43
        }
44
45 2
        return (string)$this->xml->error[0]['msg'];
46
    }
47
48
    /**
49
     * Return XML response from Wiziq
50
     *
51
     * @return \SimpleXMLElement
52
     */
53 2
    public function getResponse()
54
    {
55 2
        return $this->xml;
56
    }
57
}
58