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

valkyrjaio / valkyrja / 15738627666

18 Jun 2025 04:39PM UTC coverage: 46.073% (-1.2%) from 47.32%
15738627666

push

github

MelechMizrachi
Http/Routing: Updated to use Dispatcher2. Deprecating old way of doing things. Forcing attributes.

63 of 449 new or added lines in 18 files covered. (14.03%)

30 existing lines in 8 files now uncovered.

5109 of 11089 relevant lines covered (46.07%)

15.32 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 RuntimeException;
18
use Valkyrja\Http\Message\Constant\ContentType;
19
use Valkyrja\Http\Message\Constant\HeaderName;
20
use Valkyrja\Http\Message\Enum\StatusCode;
21
use Valkyrja\Http\Message\Response\Contract\TextResponse as Contract;
22
use Valkyrja\Http\Message\Stream\Exception\InvalidStreamException;
23
use Valkyrja\Http\Message\Stream\Stream;
24

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

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

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

60
    /**
61
     * @inheritDoc
62
     */
63
    public static function create(
64
        string|null $content = null,
65
        StatusCode|null $statusCode = null,
66
        array|null $headers = null
67
    ): static {
UNCOV
68
        return new static(
×
NEW
69
            text: $content ?? '',
×
UNCOV
70
            statusCode: $statusCode ?? static::DEFAULT_STATUS_CODE,
×
UNCOV
71
            headers: $headers ?? static::DEFAULT_HEADERS
×
UNCOV
72
        );
×
73
    }
74
}
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