Skip to content

Commit ed21563

Browse files
committed
Add type hinting
1 parent 3298ae5 commit ed21563

File tree

4 files changed

+9
-19
lines changed

4 files changed

+9
-19
lines changed

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function sendRequest(RequestInterface $request): ResponseInterface
105105
*
106106
* @return resource Socket resource
107107
*/
108-
protected function createSocket(RequestInterface $request, $remote, $useSsl)
108+
protected function createSocket(RequestInterface $request, string $remote, bool $useSsl)
109109
{
110110
$errNo = null;
111111
$errMsg = null;

src/RequestWriter.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ trait RequestWriter
1818
* Write a request to a socket.
1919
*
2020
* @param resource $socket
21-
* @param int $bufferSize
2221
*
2322
* @throws BrokenPipeException
2423
*/
25-
protected function writeRequest($socket, RequestInterface $request, $bufferSize = 8192)
24+
protected function writeRequest($socket, RequestInterface $request, int $bufferSize = 8192)
2625
{
2726
if (false === $this->fwrite($socket, $this->transformRequestHeadersToString($request))) {
2827
throw new BrokenPipeException('Failed to send request, underlying socket not accessible, (BROKEN EPIPE)', $request);
@@ -37,11 +36,10 @@ protected function writeRequest($socket, RequestInterface $request, $bufferSize
3736
* Write Body of the request.
3837
*
3938
* @param resource $socket
40-
* @param int $bufferSize
4139
*
4240
* @throws BrokenPipeException
4341
*/
44-
protected function writeBody($socket, RequestInterface $request, $bufferSize = 8192)
42+
protected function writeBody($socket, RequestInterface $request, int $bufferSize = 8192)
4543
{
4644
$body = $request->getBody();
4745

@@ -60,11 +58,8 @@ protected function writeBody($socket, RequestInterface $request, $bufferSize = 8
6058

6159
/**
6260
* Produce the header of request as a string based on a PSR Request.
63-
*
64-
*
65-
* @return string
6661
*/
67-
protected function transformRequestHeadersToString(RequestInterface $request)
62+
protected function transformRequestHeadersToString(RequestInterface $request): string
6863
{
6964
$message = vsprintf('%s %s HTTP/%s', [
7065
strtoupper($request->getMethod()),
@@ -87,11 +82,10 @@ protected function transformRequestHeadersToString(RequestInterface $request)
8782
* @see https://secure.phabricator.com/rPHU69490c53c9c2ef2002bc2dd4cecfe9a4b080b497
8883
*
8984
* @param resource $stream The stream resource
90-
* @param string $bytes Bytes written in the stream
9185
*
9286
* @return bool|int false if pipe is broken, number of bytes written otherwise
9387
*/
94-
private function fwrite($stream, $bytes)
88+
private function fwrite($stream, string $bytes)
9589
{
9690
if (!strlen($bytes)) {
9791
return 0;

src/ResponseReader.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ trait ResponseReader
2929
*
3030
* @throws TimeoutException When the socket timed out
3131
* @throws BrokenPipeException When the response cannot be read
32-
*
33-
* @return ResponseInterface
3432
*/
35-
protected function readResponse(RequestInterface $request, $socket)
33+
protected function readResponse(RequestInterface $request, $socket): ResponseInterface
3634
{
3735
$headers = [];
3836
$reason = null;
@@ -87,11 +85,9 @@ protected function readResponse(RequestInterface $request, $socket)
8785
/**
8886
* Create the stream.
8987
*
90-
* @param $socket
91-
*
92-
* @return Stream
88+
* @param resource $socket
9389
*/
94-
protected function createStream($socket, ResponseInterface $response)
90+
protected function createStream($socket, ResponseInterface $response): Stream
9591
{
9692
$size = null;
9793

src/Stream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Stream implements StreamInterface
4848
* @param resource $socket
4949
* @param int $size
5050
*/
51-
public function __construct($socket, $size = null)
51+
public function __construct($socket, ?int $size = null)
5252
{
5353
$this->socket = $socket;
5454
$this->size = $size;

0 commit comments

Comments
 (0)