Test Failed
Pull Request — master (#11)
by Pavel
23:42
created

AccessDeniedExceptionListener   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 24
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
    public function onRpcException(GetExceptionResponseEvent $event)
14
    {
15
        $request = $event->getRequest();
16
        if (!$request instanceof JsonRpcRequestInterface) {
17
            return;
18
        }
19
20
        $exception = $event->getException();
21
22
        if (!$exception instanceof AccessDeniedException) {
23
            return;
24
        }
25
26
        $event->setException(
27
            JsonRpcException::create(
28
                JsonRpcError::METHOD_NOT_FOUND,
29
                $exception->getMessage(),
30
                $exception->getTrace()
31
            )
32
        );
33
    }
34
}
35