Response::getErrorCode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 3
cts 4
cp 0.75
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.0625
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