Completed
Push — master ( 2aa80c...f80030 )
by Alexandru
08:43
created

AddsRequestIdOnResponse::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Arkitekto\RequestId library.
5
 *
6
 * (c) Alexandru Furculita <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.md.
10
 */
11
12
namespace Arki\RequestId\Integrations\Symfony\EventSubscribers;
13
14
use Arki\RequestId\Integrations\Symfony\Decorators\ResponseDecorator;
15
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
17
use Symfony\Component\HttpKernel\HttpKernelInterface;
18
use Symfony\Component\HttpKernel\KernelEvents;
19
20
/**
21
 * Adds request ID on responses.
22
 */
23 View Code Duplication
final class AddsRequestIdOnResponse implements EventSubscriberInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
{
25
    /**
26
     * @var ResponseDecorator
27
     */
28
    private $decorator;
29
30
    /**
31
     * @param ResponseDecorator $decorator
32
     */
33
    public function __construct(ResponseDecorator $decorator)
34
    {
35
        $this->decorator = $decorator;
36
    }
37
38
    /**
39
     * @param FilterResponseEvent $event
40
     */
41
    public function onResponse(FilterResponseEvent $event)
42
    {
43
        if (!$event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
44
            return;
45
        }
46
47
        $this->decorator->decorateResponse($event->getResponse());
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public static function getSubscribedEvents()
54
    {
55
        return [KernelEvents::RESPONSE => ['onResponse', -200]];
56
    }
57
}
58