Completed
Push — master ( a7ee47...bc94bf )
by Pavel
04:48
created

HttpExceptionListener::onJsonRpcException()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Bankiru\Api\JsonRpc\Listener;
4
5
use Bankiru\Api\JsonRpc\Exception\InvalidRequestException;
6
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
7
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
8
9
class HttpExceptionListener
10
{
11
    private $debug = false;
12
13
    /**
14
     * ExceptionHandlerListener constructor.
15
     *
16
     * @param bool $debug
17
     */
18 4
    public function __construct($debug)
19
    {
20 4
        $this->debug = (bool)$debug;
21 4
    }
22
23 4
    public function onJsonRpcException(GetResponseForExceptionEvent $event)
24
    {
25 4
        $exception = $event->getException();
26 4
        if ($exception instanceof InvalidRequestException) {
27 3
            $event->setException(new BadRequestHttpException($exception->getMessage(), $exception));
28 3
        }
29 4
    }
30
}
31