Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
EmptyResponse
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * This file is part of php-fast-forward/http-message.
7 *
8 * This source file is subject to the license bundled
9 * with this source code in the file LICENSE.
10 *
11 * @link      https://github.com/php-fast-forward/http-message
12 * @copyright Copyright (c) 2025 Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
13 * @license   https://opensource.org/licenses/MIT MIT License
14 */
15
16namespace FastForward\Http\Message;
17
18use Nyholm\Psr7\Response;
19
20/**
21 * Class EmptyResponse.
22 *
23 * Represents an HTTP 204 No Content response.
24 *
25 * This class MUST be used when generating responses that intentionally contain no body content,
26 * in compliance with RFC 9110. It automatically sets the HTTP status code to 204 (No Content)
27 * and applies an optional set of headers.
28 *
29 * @package FastForward\Http\Message
30 */
31final class EmptyResponse extends Response
32{
33    /**
34     * Constructs a new EmptyResponse instance with optional headers.
35     *
36     * This constructor SHALL initialize the response with HTTP status 204 and no body content.
37     * The 'reason' phrase for status 204 is automatically included based on StatusCode enumeration.
38     *
39     * @param array<string, string|string[]> $headers optional headers to include in the response
40     */
41    public function __construct(array $headers = [])
42    {
43        parent::__construct(
44            status: StatusCode::NoContent->value,
45            headers: $headers,
46            reason: StatusCode::NoContent->getReasonPhrase(),
47        );
48    }
49}