Completed
Push — master ( e35344...c8833b )
by Alexandru
21:49
created

AddsRequestIdOnResponse::onResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php // @codingStandardsIgnoreFile
2
3
namespace Arki\RequestId\Integrations\Symfony\EventSubscribers;
4
5
use Arki\RequestId\Integrations\Symfony\Decorators\ResponseDecorator;
6
use Arki\RequestId\Providers\RequestIdProvider;
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
9
use Symfony\Component\HttpKernel\HttpKernelInterface;
10
use Symfony\Component\HttpKernel\KernelEvents;
11
12
/**
13
 * Adds request ID on responses
14
 */
15 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...
16
{
17
    /**
18
     * @var ResponseDecorator
19
     */
20
    private $decorator;
21
22
    /**
23
     * @param ResponseDecorator $decorator
24
     */
25
    public function __construct(ResponseDecorator $decorator)
26
    {
27
        $this->decorator = $decorator;
28
    }
29
30
    /**
31
     * @param FilterResponseEvent $event
32
     */
33
    public function onResponse(FilterResponseEvent $event)
34
    {
35
        if (!$event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
36
            return;
37
        }
38
39
        $this->decorator->decorateResponse($event->getResponse());
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public static function getSubscribedEvents()
46
    {
47
        return [KernelEvents::RESPONSE => ['onResponse', -200]];
48
    }
49
}
50