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

systemsdk / docker-symfony-api / #74

pending completion
#74

push

DKravtsov
Php 8.2, symfony 6.2, updated RabbitMQ, updated composer dependencies, refactoring.

51 of 51 new or added lines in 44 files covered. (100.0%)

1479 of 2668 relevant lines covered (55.43%)

23.59 hits per line

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

53.85
/src/General/Transport/EventSubscriber/BodySubscriber.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\General\Transport\EventSubscriber;
6

7
use App\General\Domain\Utils\JSON;
8
use JsonException;
9
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpKernel\Event\RequestEvent;
12

13
use function in_array;
14
use function is_array;
15

16
/**
17
 * Class BodySubscriber
18
 *
19
 * @package App\General
20
 */
21
class BodySubscriber implements EventSubscriberInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     *
26
     * @return array<string, array<int, string|int>>
27
     */
28
    public static function getSubscribedEvents(): array
29
    {
30
        return [
×
31
            RequestEvent::class => [
×
32
                'onKernelRequest',
×
33
                10,
×
34
            ],
×
35
        ];
×
36
    }
37

38
    /**
39
     * Implementation of BodySubscriber event. Purpose of this is to convert JSON request data to proper request
40
     * parameters.
41
     *
42
     * @throws JsonException
43
     */
44
    public function onKernelRequest(RequestEvent $event): void
45
    {
46
        // Get current request
47
        $request = $event->getRequest();
145✔
48

49
        // If request has some content and is JSON type convert it to request parameters
50
        if ($request->getContent() !== '' && $this->isJsonRequest($request)) {
145✔
51
            $this->transformJsonBody($request);
40✔
52
        }
53
    }
54

55
    /**
56
     * Method to determine if current Request is JSON type or not.
57
     */
58
    private function isJsonRequest(Request $request): bool
59
    {
60
        return in_array($request->getContentTypeFormat(), [null, 'json', 'txt'], true);
40✔
61
    }
62

63
    /**
64
     * Method to transform JSON type request to proper request parameters.
65
     *
66
     * @throws JsonException
67
     */
68
    private function transformJsonBody(Request $request): void
69
    {
70
        $data = JSON::decode((string)$request->getContent(), true);
40✔
71

72
        if (is_array($data)) {
40✔
73
            $request->request->replace($data);
40✔
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