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

AccessDeniedExceptionListener   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 24
ccs 14
cts 15
cp 0.9333
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A onRpcException() 0 21 3
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