RequestVerifierListener::verifyRequest()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2.0078

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 13
loc 13
ccs 7
cts 8
cp 0.875
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 2.0078
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Rest\ServerBundle\EventListener;
5
6
use Innmind\Rest\Server\Request\Verifier\Verifier;
7
use Symfony\Component\{
8
    EventDispatcher\EventSubscriberInterface,
9
    HttpKernel\KernelEvents,
10
    HttpKernel\Event\GetResponseEvent
11
};
12
13 View Code Duplication
final class RequestVerifierListener 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...
14
{
15
    private $verify;
16
17 6
    public function __construct(Verifier $verifier)
18
    {
19 6
        $this->verify = $verifier;
20 6
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 38
    public static function getSubscribedEvents()
26
    {
27
        return [
28 38
            KernelEvents::REQUEST => [['verifyRequest', 24]],
29
        ];
30
    }
31
32 4
    public function verifyRequest(GetResponseEvent $event)
33
    {
34 4
        $request = $event->getRequest();
35
36 4
        if (!$request->attributes->has('_innmind_resource_definition')) {
37 2
            return;
38
        }
39
40 2
        ($this->verify)(
41 2
            $request->attributes->get('_innmind_request'),
42 2
            $request->attributes->get('_innmind_resource_definition')
43
        );
44
    }
45
}
46