• 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

0.0
/src/Valkyrja/Http/Routing/Middleware/ResponseStructMiddleware.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\Routing\Middleware;
15

16
use Override;
17
use Valkyrja\Http\Message\Request\Contract\ServerRequest;
18
use Valkyrja\Http\Message\Response\Contract\JsonResponse;
19
use Valkyrja\Http\Message\Response\Contract\Response;
20
use Valkyrja\Http\Middleware\Contract\RouteDispatchedMiddleware;
21
use Valkyrja\Http\Middleware\Handler\Contract\RouteDispatchedHandler;
22
use Valkyrja\Http\Routing\Data\Contract\Route;
23
use Valkyrja\Http\Struct\Response\Contract\ResponseStruct;
24

25
/**
26
 * Class StructRouteDispatchedMiddleware.
27
 *
28
 * @author Melech Mizrachi
29
 */
30
class ResponseStructMiddleware implements RouteDispatchedMiddleware
31
{
32
    /**
33
     * @inheritDoc
34
     */
35
    #[Override]
36
    public function routeDispatched(ServerRequest $request, Response $response, Route $route, RouteDispatchedHandler $handler): Response
37
    {
38
        $responseStruct = $route->getResponseStruct();
×
39

UNCOV
40
        if ($responseStruct !== null && $response instanceof JsonResponse) {
×
UNCOV
41
            $response = $this->updateJsonWithResponseStruct($response, $responseStruct);
×
42
        }
43

UNCOV
44
        return $handler->routeDispatched($request, $response, $route);
×
45
    }
46

47
    /**
48
     * Update the Json in a response with a given response struct.
49
     *
50
     * @param JsonResponse                 $response       The json response
51
     * @param class-string<ResponseStruct> $responseStruct The response struct
52
     *
53
     * @return JsonResponse
54
     */
55
    protected function updateJsonWithResponseStruct(JsonResponse $response, string $responseStruct): JsonResponse
56
    {
UNCOV
57
        $data = $response->getBodyAsJson();
×
58

59
        /** @psalm-suppress MixedArgumentTypeCoercion */
UNCOV
60
        return $response->withJsonAsBody($responseStruct::getStructuredData($data));
×
61
    }
62
}
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