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

RequestVerifierListener::verifyRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0078

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 8
cp 0.875
rs 9.4285
c 0
b 0
f 0
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\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