JsonResponder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 19
ccs 0
cts 9
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 9 2
A getSubscribedEvents() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\SharedKernel\Infrastructure\Responder;
6
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\EventD...ventSubscriberInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Symfony\Component\HttpFoundation\JsonResponse;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\JsonResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Symfony\Component\HttpKernel\Event\ViewEvent;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpKernel\Event\ViewEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Symfony\Component\HttpKernel\KernelEvents;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpKernel\KernelEvents was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
final class JsonResponder implements EventSubscriberInterface
13
{
14
    private const SUPPORTED_CONTENT_TYPE = 'json';
15
16
    public function __invoke(ViewEvent $viewEvent): void
17
    {
18
        $request = $viewEvent->getRequest();
19
        if (self::SUPPORTED_CONTENT_TYPE !== $request->getContentType()) {
20
            return;
21
        }
22
23
        $response = $viewEvent->getControllerResult();
24
        $viewEvent->setResponse(new JsonResponse($response->body(), $response->status()));
25
    }
26
27
    public static function getSubscribedEvents(): array
28
    {
29
        return [
30
            KernelEvents::VIEW => ['__invoke'],
31
        ];
32
    }
33
}
34