• 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

76.19
/src/Valkyrja/Http/Message/Factory/ResponseFactory.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\Factory;
15

16
use JsonException;
17
use Valkyrja\Http\Message\Enum\StatusCode;
18
use Valkyrja\Http\Message\Exception\InvalidArgumentException;
19
use Valkyrja\Http\Message\Factory\Contract\ResponseFactory as Contract;
20
use Valkyrja\Http\Message\Response\Contract\JsonResponse;
21
use Valkyrja\Http\Message\Response\Contract\RedirectResponse;
22
use Valkyrja\Http\Message\Response\Contract\Response;
23
use Valkyrja\Http\Message\Response\Contract\TextResponse;
24
use Valkyrja\Http\Message\Uri\Uri;
25

26
/**
27
 * Class ResponseFactory.
28
 *
29
 * @author Melech Mizrachi
30
 */
31
class ResponseFactory implements Contract
32
{
33
    /**
34
     * @inheritDoc
35
     */
36
    public function createResponse(
37
        string|null $content = null,
38
        StatusCode|null $statusCode = null,
39
        array|null $headers = null
40
    ): Response {
41
        return \Valkyrja\Http\Message\Response\Response::create(
2✔
42
            content: $content,
2✔
43
            statusCode: $statusCode,
2✔
44
            headers: $headers
2✔
45
        );
2✔
46
    }
47

48
    /**
49
     * @inheritDoc
50
     */
51
    public function createTextResponse(
52
        string|null $content = null,
53
        StatusCode|null $statusCode = null,
54
        array|null $headers = null
55
    ): TextResponse {
UNCOV
56
        return \Valkyrja\Http\Message\Response\TextResponse::create(
×
UNCOV
57
            content: $content,
×
UNCOV
58
            statusCode: $statusCode,
×
UNCOV
59
            headers: $headers
×
UNCOV
60
        );
×
61
    }
62

63
    /**
64
     * @inheritDoc
65
     *
66
     * @throws JsonException
67
     */
68
    public function createJsonResponse(
69
        array|null $data = null,
70
        StatusCode|null $statusCode = null,
71
        array|null $headers = null
72
    ): JsonResponse {
73
        return \Valkyrja\Http\Message\Response\JsonResponse::createFromData(
4✔
74
            data: $data,
4✔
75
            statusCode: $statusCode,
4✔
76
            headers: $headers
4✔
77
        );
4✔
78
    }
79

80
    /**
81
     * @inheritDoc
82
     *
83
     * @throws InvalidArgumentException
84
     * @throws JsonException
85
     */
86
    public function createJsonpResponse(
87
        string $callback,
88
        array|null $data = null,
89
        StatusCode|null $statusCode = null,
90
        array|null $headers = null
91
    ): JsonResponse {
92
        return $this->createJsonResponse($data, $statusCode, $headers)->withCallback($callback);
2✔
93
    }
94

95
    /**
96
     * @inheritDoc
97
     */
98
    public function createRedirectResponse(
99
        string|null $uri = null,
100
        StatusCode|null $statusCode = null,
101
        array|null $headers = null
102
    ): RedirectResponse {
103
        return \Valkyrja\Http\Message\Response\RedirectResponse::createFromUri(
2✔
104
            uri: Uri::fromString($uri ?? '/'),
2✔
105
            statusCode: $statusCode,
2✔
106
            headers: $headers
2✔
107
        );
2✔
108
    }
109
}
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