Test Failed
Pull Request — master (#11)
by Pavel
08:00
created

AccessDeniedExceptionListener::onRpcException()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 3
eloc 12
nc 3
nop 1
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