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

AddsRequestIdOnRequest::onRequest()   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\RequestDecorator;
6
use Arki\RequestId\Providers\RequestIdProvider;
7
use Arki\RequestId\RequestId;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
10
use Symfony\Component\HttpKernel\HttpKernelInterface;
11
use Symfony\Component\HttpKernel\KernelEvents;
12
13
/**
14
 * Adds request ID on requests
15
 */
16 View Code Duplication
final class AddsRequestIdOnRequest 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...
17
{
18
    /**
19
     * @var RequestDecorator
20
     */
21
    private $decorator;
22
23
    /**
24
     * @param RequestDecorator $decorator
25
     */
26
    public function __construct(RequestDecorator $decorator)
27
    {
28
        $this->decorator = $decorator;
29
    }
30
31
    /**
32
     * @param GetResponseEvent $event
33
     */
34
    public function onRequest(GetResponseEvent $event)
35
    {
36
        if (!$event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
37
            return;
38
        }
39
40
        $this->decorator->decorateRequest($event->getRequest());
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public static function getSubscribedEvents()
47
    {
48
        return [KernelEvents::REQUEST => ['onRequest', 200]];
49
    }
50
}
51