Completed
Push — develop ( dd6a23...99c8cd )
by Baptiste
06:26
created

RequestVerifierListener   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 33
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 6 1
A verifyRequest() 0 13 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Rest\ServerBundle\EventListener;
5
6
use Innmind\Rest\Server\RequestVerifier\VerifierInterface;
7
use Symfony\Component\{
8
    EventDispatcher\EventSubscriberInterface,
9
    HttpKernel\KernelEvents,
10
    HttpKernel\Event\GetResponseEvent
11
};
12
13
final class RequestVerifierListener implements EventSubscriberInterface
14
{
15
    private $verifier;
16
17 3
    public function __construct(VerifierInterface $verifier)
18
    {
19 3
        $this->verifier = $verifier;
20 3
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 1
    public static function getSubscribedEvents()
26
    {
27
        return [
28 1
            KernelEvents::REQUEST => [['verifyRequest', 24]],
29
        ];
30
    }
31
32 2
    public function verifyRequest(GetResponseEvent $event)
33
    {
34 2
        $request = $event->getRequest();
35
36 2
        if (!$request->attributes->has('_innmind_resource_definition')) {
37 1
            return;
38
        }
39
40 1
        $this->verifier->verify(
41 1
            $request->attributes->get('_innmind_request'),
42 1
            $request->attributes->get('_innmind_resource_definition')
43
        );
44
    }
45
}
46