Result   A
last analyzed

Complexity

Total Complexity 23

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 23
eloc 81
c 5
b 0
f 0
dl 0
loc 155
rs 10

17 Methods

Rating   Name   Duplication   Size   Complexity  
A isOk() 0 3 1
A getHeaders() 0 3 1
A isClientError() 0 3 2
A getResponseObject() 0 3 1
A isInformational() 0 3 2
A isServerError() 0 3 2
A getContentType() 0 3 1
A getReasonPhrase() 0 3 1
A getResponseArray() 0 3 1
A __construct() 0 5 1
A isError() 0 3 2
A isSuccess() 0 3 2
A getResponseCode() 0 3 1
A isRedirect() 0 3 2
A getDescription() 0 3 1
A isNotFound() 0 3 1
A getResponse() 0 3 1
1
<?php
2
3
// Result.php
4
#################################################
5
##
6
## PHPLicengine
7
##
8
#################################################
9
## Copyright 2009-{current_year} PHPLicengine
10
## 
11
## Licensed under the Apache License, Version 2.0 (the "License");
12
## you may not use this file except in compliance with the License.
13
## You may obtain a copy of the License at
14
##
15
##    http://www.apache.org/licenses/LICENSE-2.0
16
##
17
## Unless required by applicable law or agreed to in writing, software
18
## distributed under the License is distributed on an "AS IS" BASIS,
19
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
## See the License for the specific language governing permissions and
21
## limitations under the License.
22
#################################################
23
24
namespace PHPLicengine\Api;
25
26
class Result {
27
28
       protected $headers;
29
       protected $curlInfo;
30
       protected $body;
31
       protected $reasonPhrases = array(
32
                     // INFORMATIONAL CODES
33
                     100 => 'Continue',
34
                     101 => 'Switching Protocols',
35
                     102 => 'Processing',
36
                     // SUCCESS CODES
37
                     200 => 'OK',
38
                     201 => 'Created',
39
                     202 => 'Accepted',
40
                     203 => 'Non-Authoritative Information',
41
                     204 => 'No Content',
42
                     205 => 'Reset Content',
43
                     206 => 'Partial Content',
44
                     207 => 'Multi-status',
45
                     208 => 'Already Reported',
46
                     // REDIRECTION CODES
47
                     300 => 'Multiple Choices',
48
                     301 => 'Moved Permanently',
49
                     302 => 'Found',
50
                     303 => 'See Other',
51
                     304 => 'Not Modified',
52
                     305 => 'Use Proxy',
53
                     306 => 'Switch Proxy', // Deprecated
54
                     307 => 'Temporary Redirect',
55
                     // CLIENT ERROR
56
                     400 => 'Bad Request',
57
                     401 => 'Unauthorized',
58
                     402 => 'Payment Required',
59
                     403 => 'Forbidden',
60
                     404 => 'Not Found',
61
                     405 => 'Method Not Allowed',
62
                     406 => 'Not Acceptable',
63
                     407 => 'Proxy Authentication Required',
64
                     408 => 'Request Time-out',
65
                     409 => 'Conflict',
66
                     410 => 'Gone',
67
                     411 => 'Length Required',
68
                     412 => 'Precondition Failed',
69
                     413 => 'Request Entity Too Large',
70
                     414 => 'Request-URI Too Large',
71
                     415 => 'Unsupported Media Type',
72
                     416 => 'Requested range not satisfiable',
73
                     417 => 'Expectation Failed',
74
                     418 => 'I\'m a teapot',
75
                     422 => 'Unprocessable Entity',
76
                     423 => 'Locked',
77
                     424 => 'Failed Dependency',
78
                     425 => 'Unordered Collection',
79
                     426 => 'Upgrade Required',
80
                     428 => 'Precondition Required',
81
                     429 => 'Too Many Requests',
82
                     431 => 'Request Header Fields Too Large',
83
                     // SERVER ERROR
84
                     500 => 'Internal Server Error',
85
                     501 => 'Not Implemented',
86
                     502 => 'Bad Gateway',
87
                     503 => 'Service Unavailable',
88
                     504 => 'Gateway Time-out',
89
                     505 => 'HTTP Version not supported',
90
                     506 => 'Variant Also Negotiates',
91
                     507 => 'Insufficient Storage',
92
                     508 => 'Loop Detected',
93
                     511 => 'Network Authentication Required'
94
       );
95
96
       public function __construct($body, $headers, $curlInfo) 
97
       {
98
              $this->body = $body;
99
              $this->headers = $headers;
100
              $this->curlInfo = $curlInfo;
101
       }
102
103
       public function isError() 
104
       {
105
              return isset($this->getResponseObject()->errors) && $this->getResponseObject()->errors;
106
       }
107
     
108
       public function getDescription() 
109
       {
110
              return $this->getResponseObject()->description;
111
       }
112
113
       public function getHeaders()
114
       {
115
              return $this->headers;
116
       }
117
118
       public function getResponse()
119
       {
120
              return $this->body;
121
       }
122
123
       public function getResponseObject() 
124
       {
125
              return json_decode($this->body);
126
       }
127
128
       public function getResponseArray() 
129
       {
130
              return json_decode($this->body, true);
131
       }
132
133
       public function getResponseCode()
134
       {
135
              return $this->curlInfo['http_code'];
136
       }
137
138
       public function getReasonPhrase()
139
       {
140
              return $this->reasonPhrases[$this->curlInfo['http_code']];
141
       }
142
143
       public function getContentType()
144
       {
145
              return $this->curlInfo['content_type'];
146
       }
147
148
       public function isOk()
149
       {
150
              return ($this->curlInfo['http_code'] === 200);
151
       }
152
153
       public function isSuccess()
154
       {
155
              return (200 <= $this->curlInfo['http_code'] && 300 > $this->curlInfo['http_code']);
156
       }
157
158
       public function isNotFound()
159
       {
160
              return ($this->curlInfo['http_code'] === 404);
161
       }
162
163
       public function isInformational()
164
       {
165
              return ($this->curlInfo['http_code'] >= 100 && $this->curlInfo['http_code'] < 200);
166
       }
167
168
       public function isRedirect()
169
       {
170
              return (300 <= $this->curlInfo['http_code'] && 400 > $this->curlInfo['http_code']);
171
       }
172
173
       public function isClientError()
174
       {
175
              return ($this->curlInfo['http_code'] < 500 && $this->curlInfo['http_code'] >= 400);
176
       }
177
178
       public function isServerError()
179
       {
180
              return (500 <= $this->curlInfo['http_code'] && 600 > $this->curlInfo['http_code']);
181
       }
182
183
}
184