1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2015 BuzzBoard, Inc. |
5
|
|
|
* |
6
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
7
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
8
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
9
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
10
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
11
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
12
|
|
|
* DEALINGS IN THE SOFTWARE. |
13
|
|
|
* |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace BuzzBoard\Network; |
17
|
|
|
|
18
|
|
|
use BuzzBoard\Profile; |
19
|
|
|
use BuzzBoard\Exceptions\RequestFailedException; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class BuzzBoard\Network\Response |
23
|
|
|
* |
24
|
|
|
* @package BuzzBoard |
25
|
|
|
*/ |
26
|
|
|
class Response { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @const Http Success code |
30
|
|
|
*/ |
31
|
|
|
const SUCCESS_CODE = 200; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* |
35
|
|
|
* @var type |
36
|
|
|
*/ |
37
|
|
|
protected $response; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* |
41
|
|
|
* @param \GuzzleHttp\Client $response |
42
|
|
|
*/ |
43
|
|
|
public function __construct(\GuzzleHttp\Psr7\Response $response) { |
44
|
|
|
$this->response = $response; |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* |
49
|
|
|
* @return int |
50
|
|
|
*/ |
51
|
|
|
public function getStatusCode() { |
52
|
|
|
return (int) !empty($this->response) ? $this->response->code : 0; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* |
57
|
|
|
* @return type |
58
|
|
|
* @throws RequestFailedException |
59
|
|
|
*/ |
60
|
|
|
public function getBody() { |
61
|
|
|
$body = (string) $this->response->getBody(); |
62
|
|
|
$response = json_decode($body); |
63
|
|
|
|
64
|
|
|
$response->code = (int) $response->code; |
65
|
|
|
|
66
|
|
|
if ( |
67
|
|
|
!in_array($response->code, [ |
68
|
|
|
self::SUCCESS_CODE, |
69
|
|
|
Profile::PROFILE_CREATED_RESPONSE_CODE |
70
|
|
|
]) |
71
|
|
|
) { |
72
|
|
|
throw new RequestFailedException(sprintf('%s', $response->message), E_USER_ERROR); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $response; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..