ResponseSubscriber::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/EventSubscriber/ResponseSubscriber.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\EventSubscriber;
10
11
use App\Service\Version;
0 ignored issues
show
Bug introduced by
The type App\Service\Version 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...
12
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
13
use Symfony\Component\HttpKernel\Event\ResponseEvent;
14
15
/**
16
 * Class ResponseSubscriber
17
 *
18
 * @package App\EventSubscriber
19
 * @author TLe, Tarmo Leppänen <[email protected]>
20
 */
21
class ResponseSubscriber implements EventSubscriberInterface
22
{
23 597
    public function __construct(
24
        private readonly Version $version,
25
    ) {
26 597
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 1
    public static function getSubscribedEvents(): array
32
    {
33 1
        return [
34 1
            ResponseEvent::class => [
35 1
                'onKernelResponse',
36 1
                10,
37 1
            ],
38 1
        ];
39
    }
40
41
    /**
42
     * Subscriber method to attach API version to every response.
43
     */
44 597
    public function onKernelResponse(ResponseEvent $event): void
45
    {
46
        // Attach new header
47 597
        $event->getResponse()->headers->add([
48 597
            'X-API-VERSION' => $this->version->get(),
49 597
        ]);
50
    }
51
}
52