Response   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 0
dl 0
loc 58
ccs 13
cts 13
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __get() 0 12 3
A toArray() 0 4 1
A toJson() 0 4 1
1
<?php
2
3
/**
4
 * xOrder Response.
5
 *
6
 * @package     craftt/xorder-sdk
7
 * @author      Ryan Stratton <[email protected]>
8
 * @copyright   Copyright (c) Ryan Stratton
9
 * @license     https://github.com/craftt/xorder-php-sdk/blob/master/LICENSE.md Apache 2.0
10
 * @link        https://github.com/craftt/xorder-php-sdk
11
 */
12
13
namespace XOrder;
14
15
use SimpleXMLElement;
16
use XOrder\Contracts\ResponseInterface;
17
18
/**
19
 * Session
20
 */
21
class Response implements ResponseInterface
22
{
23
24
    /**
25
     * @var \SimpleXMLElement
26
     */
27
    private $data;
28
29
    /**
30
     * Constructor
31
     *
32
     * @param string $xml
33
     */
34 12
    public function __construct($xml)
35
    {
36 12
        $this->data = new SimpleXMLElement($xml);
37 12
    }
38
39
    /**
40
     * Property overloader.
41
     *
42
     * @param  string $property
43
     * @throws \ErrorException
44
     * @return mixed
45
     */
46 6
    public function __get($property)
47
    {
48 6
        if ($property === 'data') {
49 2
            return $this->data;
50
        }
51
52 4
        if (property_exists($this->data, $property)) {
53 2
            return $this->data->$property;
54
        }
55
56 2
        return null;
57
    }
58
59
    /**
60
     * Covert XML response data to array.
61
     *
62
     * @return array
63
     */
64 2
    public function toArray()
65
    {
66 2
        return json_decode($this->toJson(), true);
67
    }
68
69
    /**
70
     * Convery XML response data to JSON.
71
     *
72
     * @return string
73
     */
74 4
    public function toJson()
75
    {
76 4
        return json_encode($this->data);
77
    }
78
}
79