• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

valkyrjaio / valkyrja / 16185661246

10 Jul 2025 03:48AM UTC coverage: 43.558% (-0.2%) from 43.747%
16185661246

push

github

MelechMizrachi
Http Routing: Updating ListCommand.

0 of 21 new or added lines in 1 file covered. (0.0%)

2913 existing lines in 212 files now uncovered.

3925 of 9011 relevant lines covered (43.56%)

11.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.54
/src/Valkyrja/Http/Message/Response/TextResponse.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <melechmizrachi@gmail.com>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace Valkyrja\Http\Message\Response;
15

16
use InvalidArgumentException;
17
use Override;
18
use RuntimeException;
19
use Valkyrja\Http\Message\Constant\ContentType;
20
use Valkyrja\Http\Message\Constant\HeaderName;
21
use Valkyrja\Http\Message\Enum\StatusCode;
22
use Valkyrja\Http\Message\Response\Contract\TextResponse as Contract;
23
use Valkyrja\Http\Message\Stream\Exception\InvalidStreamException;
24
use Valkyrja\Http\Message\Stream\Stream;
25

26
/**
27
 * Class TextResponse.
28
 *
29
 * @author Melech Mizrachi
30
 */
31
class TextResponse extends Response implements Contract
32
{
33
    /**
34
     * NativeTextResponse constructor.
35
     *
36
     * @param string                  $text       The text
37
     * @param StatusCode              $statusCode [optional] The status
38
     * @param array<string, string[]> $headers    [optional] The headers
39
     *
40
     * @throws InvalidArgumentException
41
     * @throws RuntimeException
42
     * @throws InvalidStreamException
43
     */
44
    public function __construct(
45
        string $text = self::DEFAULT_CONTENT,
46
        StatusCode $statusCode = self::DEFAULT_STATUS_CODE,
47
        array $headers = self::DEFAULT_HEADERS
48
    ) {
49
        $body = new Stream();
4✔
50

51
        $body->write($text);
4✔
52
        $body->rewind();
4✔
53

54
        parent::__construct(
4✔
55
            $body,
4✔
56
            $statusCode,
4✔
57
            $this->injectHeader(HeaderName::CONTENT_TYPE, ContentType::TEXT_PLAIN_UTF8, $headers, true)
4✔
58
        );
4✔
59
    }
60

61
    /**
62
     * @inheritDoc
63
     */
64
    #[Override]
65
    public static function create(
66
        string|null $content = null,
67
        StatusCode|null $statusCode = null,
68
        array|null $headers = null
69
    ): static {
70
        return new static(
×
71
            text: $content ?? '',
×
72
            statusCode: $statusCode ?? static::DEFAULT_STATUS_CODE,
×
UNCOV
73
            headers: $headers ?? static::DEFAULT_HEADERS
×
UNCOV
74
        );
×
75
    }
76
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc