Passed
Push — master ( 5036c2...3ecdb9 )
by Thierry
05:43 queued 02:26
created

ExceptionSubscriber::handleException()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 7
nc 2
nop 1
dl 0
loc 10
ccs 8
cts 8
cp 1
crap 5
rs 8.8571
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace lepiaf\SapientBundle\EventSubscriber;
5
6
use lepiaf\SapientBundle\Exception\NoKeyFoundForRequesterException;
7
use lepiaf\SapientBundle\Exception\RequesterHeaderMissingException;
8
use lepiaf\SapientBundle\Exception\SignerHeaderMissingException;
9
use lepiaf\SapientBundle\Exception\VerifyRequestException;
10
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
12
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
13
use Symfony\Component\HttpKernel\KernelEvents;
14
15
class ExceptionSubscriber implements EventSubscriberInterface
16
{
17 1
    public static function getSubscribedEvents()
18
    {
19
        return [
20 1
            KernelEvents::EXCEPTION => 'handleException',
21
        ];
22
    }
23
24 5
    public function handleException(GetResponseForExceptionEvent $event): void
25
    {
26 5
        $exception = $event->getException();
27 5
        if ($exception instanceof NoKeyFoundForRequesterException
28 4
            || $exception instanceof RequesterHeaderMissingException
29 3
            || $exception instanceof SignerHeaderMissingException
30 5
            || $exception instanceof VerifyRequestException
31
        ) {
32 4
            $event->setException(new BadRequestHttpException($exception->getMessage()));
33 4
            $event->stopPropagation();
34
        }
35 5
    }
36
}
37