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

ExceptionSubscriber   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 4 1
B handleException() 0 10 5
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