|
2 | 2 |
|
3 | 3 | namespace SparkPost; |
4 | 4 |
|
| 5 | +use Psr\Http\Message\MessageInterface; |
5 | 6 | use Psr\Http\Message\ResponseInterface as ResponseInterface; |
6 | 7 | use Psr\Http\Message\StreamInterface as StreamInterface; |
7 | 8 |
|
@@ -39,84 +40,83 @@ public function getRequest() |
39 | 40 | } |
40 | 41 |
|
41 | 42 | /** |
42 | | - * Returns the body. |
| 43 | + * Gets the body in json format. |
43 | 44 | * |
44 | | - * @return array $body - the json decoded body from the http response |
| 45 | + * @return array Decoded body. |
45 | 46 | */ |
46 | | - public function getBody() |
47 | | - { |
48 | | - $body = $this->response->getBody(); |
49 | | - $body_string = $body->__toString(); |
50 | | - |
51 | | - $json = json_decode($body_string, true); |
| 47 | + public function getBodyAsJson() : array { |
| 48 | + return json_decode($this->getBody()->getContents(), true); |
| 49 | + } |
52 | 50 |
|
53 | | - return $json; |
| 51 | + public function getBody() : StreamInterface |
| 52 | + { |
| 53 | + return $this->response->getBody(); |
54 | 54 | } |
55 | 55 |
|
56 | 56 | /** |
57 | 57 | * pass these down to the response given in the constructor. |
58 | 58 | */ |
59 | | - public function getProtocolVersion() |
| 59 | + public function getProtocolVersion() : string |
60 | 60 | { |
61 | 61 | return $this->response->getProtocolVersion(); |
62 | 62 | } |
63 | 63 |
|
64 | | - public function withProtocolVersion($version) |
| 64 | + public function withProtocolVersion($version) : MessageInterface |
65 | 65 | { |
66 | 66 | return $this->response->withProtocolVersion($version); |
67 | 67 | } |
68 | 68 |
|
69 | | - public function getHeaders() |
| 69 | + public function getHeaders() : array |
70 | 70 | { |
71 | 71 | return $this->response->getHeaders(); |
72 | 72 | } |
73 | 73 |
|
74 | | - public function hasHeader($name) |
| 74 | + public function hasHeader($name) : bool |
75 | 75 | { |
76 | 76 | return $this->response->hasHeader($name); |
77 | 77 | } |
78 | 78 |
|
79 | | - public function getHeader($name) |
| 79 | + public function getHeader($name) : array |
80 | 80 | { |
81 | 81 | return $this->response->getHeader($name); |
82 | 82 | } |
83 | 83 |
|
84 | | - public function getHeaderLine($name) |
| 84 | + public function getHeaderLine($name) : string |
85 | 85 | { |
86 | 86 | return $this->response->getHeaderLine($name); |
87 | 87 | } |
88 | 88 |
|
89 | | - public function withHeader($name, $value) |
| 89 | + public function withHeader($name, $value) : MessageInterface |
90 | 90 | { |
91 | 91 | return $this->response->withHeader($name, $value); |
92 | 92 | } |
93 | 93 |
|
94 | | - public function withAddedHeader($name, $value) |
| 94 | + public function withAddedHeader($name, $value) : MessageInterface |
95 | 95 | { |
96 | 96 | return $this->response->withAddedHeader($name, $value); |
97 | 97 | } |
98 | 98 |
|
99 | | - public function withoutHeader($name) |
| 99 | + public function withoutHeader($name) : MessageInterface |
100 | 100 | { |
101 | 101 | return $this->response->withoutHeader($name); |
102 | 102 | } |
103 | 103 |
|
104 | | - public function withBody(StreamInterface $body) |
| 104 | + public function withBody(StreamInterface $body) : MessageInterface |
105 | 105 | { |
106 | 106 | return $this->response->withBody($body); |
107 | 107 | } |
108 | 108 |
|
109 | | - public function getStatusCode() |
| 109 | + public function getStatusCode() : int |
110 | 110 | { |
111 | 111 | return $this->response->getStatusCode(); |
112 | 112 | } |
113 | 113 |
|
114 | | - public function withStatus($code, $reasonPhrase = '') |
| 114 | + public function withStatus($code, $reasonPhrase = '') : ResponseInterface |
115 | 115 | { |
116 | 116 | return $this->response->withStatus($code, $reasonPhrase); |
117 | 117 | } |
118 | 118 |
|
119 | | - public function getReasonPhrase() |
| 119 | + public function getReasonPhrase() : string |
120 | 120 | { |
121 | 121 | return $this->response->getReasonPhrase(); |
122 | 122 | } |
|
0 commit comments