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 * @copyright Copyright (c) 2025-2026 Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
12 * @license   https://opensource.org/licenses/MIT MIT License
13 *
14 * @see       https://github.com/php-fast-forward/http-message
15 * @see       https://github.com/php-fast-forward
16 * @see       https://datatracker.ietf.org/doc/html/rfc2119
17 */
18
19namespace FastForward\Http\Message;
20
21use Nyholm\Psr7\Response;
22
23/**
24 * Class EmptyResponse.
25 *
26 * Represents an HTTP 204 No Content response.
27 *
28 * This class MUST be used when generating responses that intentionally contain no body content,
29 * in compliance with RFC 9110. It automatically sets the HTTP status code to 204 (No Content)
30 * and applies an optional set of headers.
31 */
32final class EmptyResponse extends Response
33{
34    /**
35     * Constructs a new EmptyResponse instance with optional headers.
36     *
37     * This constructor SHALL initialize the response with HTTP status 204 and no body content.
38     * The 'reason' phrase for status 204 is automatically included based on StatusCode enumeration.
39     *
40     * @param array $headers optional headers to include in the response
41     */
42    public function __construct(array $headers = [])
43    {
44        parent::__construct(
45            status: StatusCode::NoContent->value,
46            headers: $headers,
47            reason: StatusCode::NoContent->getReasonPhrase(),
48        );
49    }
50}