Completed
Push — master ( cc125e...c31978 )
by Tomas
04:15
created

ConsoleResponse::getPostFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Tomaj\NetteApi\Misc;
4
5
class ConsoleResponse
6
{
7
    private $postFields;
8
9
    private $getFields;
10
11
    private $url;
12
13
    private $method;
14
15
    private $headers;
16
17
    private $responseCode;
18
19
    private $responseBody;
20
21
    private $responseTime;
22
23
    private $isError = false;
24
25
    private $errorNumber;
26
27
    private $errorMessage;
28
29
    public function __construct($url, $method, $postFields, $getFields, $headers)
30
    {
31
        $this->url = $url;
32
        $this->method = $method;
33
        $this->postFields = $postFields;
34
        $this->getFields = $getFields;
35
        $this->headers = $headers;
36
    }
37
38
    public function logRequest($responseCode, $responseBody, $responseTime)
39
    {
40
        $this->responseCode = $responseCode;
41
        $this->responseBody = $responseBody;
42
        $this->responseTime = $responseTime;
43
    }
44
45
    public function logError($errorNumber, $errorMessage, $responseTime)
46
    {
47
        $this->isError = true;
48
        $this->errorNumber = $errorNumber;
49
        $this->errorMessage = $errorMessage;
50
        $this->responseTime = $responseTime;
51
    }
52
53
    public function getPostFields()
54
    {
55
        return $this->postFields;
56
    }
57
58
    public function getGetFields()
59
    {
60
        return $this->getFields;
61
    }
62
63
    public function getUrl()
64
    {
65
        return $this->url;
66
    }
67
68
    public function getMethod()
69
    {
70
        return $this->method;
71
    }
72
73
    public function getHeaders()
74
    {
75
        return $this->headers;
76
    }
77
78
    public function isError()
79
    {
80
        return $this->isError;
81
    }
82
83
    /**
84
     * @return integer
85
     */
86
    public function getResponseCode()
87
    {
88
        return $this->responseCode;
89
    }
90
91
    /**
92
     * @return string
93
     */
94
    public function getResponseBody()
95
    {
96
        return $this->responseBody;
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function getFormattedJsonBody()
103
    {
104
        $body = $this->responseBody;
105
        $decoded = json_decode($body);
106
        if ($decoded) {
107
            $body = json_encode($decoded, JSON_PRETTY_PRINT);
108
        }
109
        return $body;
110
    }
111
112
    /**
113
     * @return integer
114
     */
115
    public function getResponseTime()
116
    {
117
        return $this->responseTime;
118
    }
119
120
    /**
121
     * @return integer
122
     */
123
    public function getErrorNumber()
124
    {
125
        return $this->errorNumber;
126
    }
127
128
    /**
129
     * @return string
130
     */
131
    public function getErrorMessage()
132
    {
133
        return $this->errorMessage;
134
    }
135
}
136