From 42961753377767b837907763af7d4ee637d6dcb8 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Tue, 2 Feb 2021 00:58:37 +0300 Subject: [PATCH] Remove SapiEmitter return --- src/SapiEmitter.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/SapiEmitter.php b/src/SapiEmitter.php index 4347f2b91..5130d4730 100644 --- a/src/SapiEmitter.php +++ b/src/SapiEmitter.php @@ -14,7 +14,7 @@ use function strtolower; /** - * SapiEmitter sends a response using PHP Server API + * SapiEmitter sends a response using PHP Server API. */ final class SapiEmitter { @@ -34,7 +34,7 @@ final class SapiEmitter public function __construct(int $bufferSize = null) { if ($bufferSize !== null && $bufferSize <= 0) { - throw new InvalidArgumentException('Buffer size must be greater than zero'); + throw new InvalidArgumentException('Buffer size must be greater than zero.'); } $this->bufferSize = $bufferSize ?? self::DEFAULT_BUFFER_SIZE; } @@ -46,10 +46,8 @@ public function __construct(int $bufferSize = null) * @param bool $withoutBody If body should be ignored. * * @throws HeadersHaveBeenSentException - * - * @return bool */ - public function emit(ResponseInterface $response, bool $withoutBody = false): bool + public function emit(ResponseInterface $response, bool $withoutBody = false): void { $status = $response->getStatusCode(); $withoutBody = $withoutBody || !$this->shouldOutputBody($response); @@ -58,19 +56,21 @@ public function emit(ResponseInterface $response, bool $withoutBody = false): bo $response = $response->withoutHeader('Content-Length'); } - // we can't send headers if they are already sent + // We can't send headers if they are already sent. if (headers_sent()) { throw new HeadersHaveBeenSentException(); } header_remove(); - // send HTTP Status-Line + + // Send HTTP Status-Line. header(sprintf( 'HTTP/%s %d %s', $response->getProtocolVersion(), $status, $response->getReasonPhrase() ), true, $status); - // send headers + + // Send headers. foreach ($response->getHeaders() as $header => $values) { $replaceFirst = strtolower($header) !== 'set-cookie'; foreach ($values as $value) { @@ -89,8 +89,6 @@ public function emit(ResponseInterface $response, bool $withoutBody = false): bo $this->emitBody($response); } - - return true; } private function emitBody(ResponseInterface $response): void @@ -110,7 +108,7 @@ private function shouldOutputBody(ResponseInterface $response): bool if (in_array($response->getStatusCode(), self::NO_BODY_RESPONSE_CODES, true)) { return false; } - // check if body is empty + // Check if body is empty. $body = $response->getBody(); if (!$body->isReadable()) { return false;