Passed
Pull Request — master (#11)
by Pavel
07:02
created

AccessDeniedExceptionListener::onRpcException()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3.0026

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 14
cts 15
cp 0.9333
rs 9.3142
c 0
b 0
f 0
cc 3
eloc 12
nc 3
nop 1
crap 3.0026
1
<?php
2
3
namespace Bankiru\Api\JsonRpc\Listener;
4
5
use Bankiru\Api\JsonRpc\Exception\JsonRpcException;
6
use Bankiru\Api\Rpc\Event\GetExceptionResponseEvent;
7
use ScayTrase\Api\JsonRpc\JsonRpcError;
8
use ScayTrase\Api\JsonRpc\JsonRpcRequestInterface;
9
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
10
11
final class AccessDeniedExceptionListener
12
{
13 2
    public function onRpcException(GetExceptionResponseEvent $event)
14
    {
15 2
        $request = $event->getRequest();
16 2
        if (!$request instanceof JsonRpcRequestInterface) {
17
            return;
18
        }
19
20 2
        $exception = $event->getException();
21
22 2
        if (!$exception instanceof AccessDeniedException) {
23 1
            return;
24
        }
25
26 1
        $event->setException(
27 1
            JsonRpcException::create(
28 1
                JsonRpcError::METHOD_NOT_FOUND,
29 1
                $exception->getMessage(),
30 1
                $exception->getTrace()
31 1
            )
32 1
        );
33 1
    }
34
}
35