Completed
Push — master ( 2aa80c...f80030 )
by Alexandru
08:43
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
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\RequestDecorator;
15
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
17
use Symfony\Component\HttpKernel\HttpKernelInterface;
18
use Symfony\Component\HttpKernel\KernelEvents;
19
20
/**
21
 * Adds request ID on requests.
22
 */
23 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...
24
{
25
    /**
26
     * @var RequestDecorator
27
     */
28
    private $decorator;
29
30
    /**
31
     * @param RequestDecorator $decorator
32
     */
33
    public function __construct(RequestDecorator $decorator)
34
    {
35
        $this->decorator = $decorator;
36
    }
37
38
    /**
39
     * @param GetResponseEvent $event
40
     */
41
    public function onRequest(GetResponseEvent $event)
42
    {
43
        if (!$event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
44
            return;
45
        }
46
47
        $this->decorator->decorateRequest($event->getRequest());
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public static function getSubscribedEvents()
54
    {
55
        return [KernelEvents::REQUEST => ['onRequest', 200]];
56
    }
57
}
58