Completed
Pull Request — master (#104)
by
unknown
03:28
created

HttpResult::getResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 6
1
<?php
2
3
namespace eXpansion\Framework\Core\Helpers\Structures;
4
5
class HttpResult
6
{
7
    /** @var  CurlInfo */
8
    protected $curlInfo;
9
10
    /** @var  string */
11
    protected $error;
12
13
    /** @var  string */
14
    protected $response;
15
16
    /** @var  mixed */
17
    protected $additionalData;
18
19
    /**
20
     * @return null|string
21
     */
22
    public function getResponse()
23
    {
24
        if (!$this->hasError()) {
25
            return $this->response;
26
        } else {
27
            return null;
28
        }
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getError()
35
    {
36
        return $this->error;
37
    }
38
39
40
    /**
41
     * @return CurlInfo
42
     */
43
    public function getInfo()
44
    {
45
        return $this->curlInfo;
46
    }
47
48
    /**
49
     * @return integer|null
50
     */
51
    public function getHttpCode()
52
    {
53
        return $this->curlInfo->http_code;
54
    }
55
56
57
    /**
58
     * HttpResult constructor.
59
     * @param $data
60
     * @param $curlInfo
61
     * @param $error
62
     * @param $additionalData
63
     */
64
    public function __construct($data, $curlInfo, $error, $additionalData)
65
    {
66
        $this->response = $data;
67
68
        $this->curlInfo = new CurlInfo($curlInfo);
69
        $this->error = $error;
70
        $this->additionalData = $additionalData;
71
    }
72
73
    /**
74
     * @return bool
75
     */
76
    public function hasError()
77
    {
78
        if (empty($this->error) && $this->getHttpCode() == 200) {
79
            return false;
80
        }
81
82
        return true;
83
    }
84
85
    /**
86
     * @return mixed
87
     */
88
    public function getAdditionalData()
89
    {
90
        return $this->additionalData;
91
    }
92
93
}
94