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

AddsRequestIdOnRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 35
loc 35
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A onRequest() 8 8 2
A getSubscribedEvents() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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