Skip to content

Commit c24d003

Browse files
committed
Issue SparkPost#212: Compatibility with psr/http-message 2.0
1 parent bb912ec commit c24d003

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

lib/SparkPost/SparkPostResponse.php

+17-15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace SparkPost;
44

5+
use GuzzleHttp\Psr7\Stream;
6+
use Psr\Http\Message\MessageInterface;
57
use Psr\Http\Message\ResponseInterface as ResponseInterface;
68
use Psr\Http\Message\StreamInterface as StreamInterface;
79

@@ -43,80 +45,80 @@ public function getRequest()
4345
*
4446
* @return array $body - the json decoded body from the http response
4547
*/
46-
public function getBody()
48+
public function getBody() : StreamInterface
4749
{
4850
$body = $this->response->getBody();
4951
$body_string = $body->__toString();
5052

5153
$json = json_decode($body_string, true);
5254

53-
return $json;
55+
return new Stream($json);
5456
}
5557

5658
/**
5759
* pass these down to the response given in the constructor.
5860
*/
59-
public function getProtocolVersion()
61+
public function getProtocolVersion() : string
6062
{
6163
return $this->response->getProtocolVersion();
6264
}
6365

64-
public function withProtocolVersion($version)
66+
public function withProtocolVersion($version) : MessageInterface
6567
{
6668
return $this->response->withProtocolVersion($version);
6769
}
6870

69-
public function getHeaders()
71+
public function getHeaders() : array
7072
{
7173
return $this->response->getHeaders();
7274
}
7375

74-
public function hasHeader($name)
76+
public function hasHeader($name) : bool
7577
{
7678
return $this->response->hasHeader($name);
7779
}
7880

79-
public function getHeader($name)
81+
public function getHeader($name) : array
8082
{
8183
return $this->response->getHeader($name);
8284
}
8385

84-
public function getHeaderLine($name)
86+
public function getHeaderLine($name) : string
8587
{
8688
return $this->response->getHeaderLine($name);
8789
}
8890

89-
public function withHeader($name, $value)
91+
public function withHeader($name, $value) : MessageInterface
9092
{
9193
return $this->response->withHeader($name, $value);
9294
}
9395

94-
public function withAddedHeader($name, $value)
96+
public function withAddedHeader($name, $value) : MessageInterface
9597
{
9698
return $this->response->withAddedHeader($name, $value);
9799
}
98100

99-
public function withoutHeader($name)
101+
public function withoutHeader($name) : MessageInterface
100102
{
101103
return $this->response->withoutHeader($name);
102104
}
103105

104-
public function withBody(StreamInterface $body)
106+
public function withBody(StreamInterface $body) : MessageInterface
105107
{
106108
return $this->response->withBody($body);
107109
}
108110

109-
public function getStatusCode()
111+
public function getStatusCode() : int
110112
{
111113
return $this->response->getStatusCode();
112114
}
113115

114-
public function withStatus($code, $reasonPhrase = '')
116+
public function withStatus($code, $reasonPhrase = '') : ResponseInterface
115117
{
116118
return $this->response->withStatus($code, $reasonPhrase);
117119
}
118120

119-
public function getReasonPhrase()
121+
public function getReasonPhrase() : string
120122
{
121123
return $this->response->getReasonPhrase();
122124
}

0 commit comments

Comments
 (0)