| Conditions | 5 |
| Paths | 4 |
| Total Lines | 17 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | 4 | public function createFor(\Exception $exception) : JsonRpcExceptionInterface |
|
| 24 | { |
||
| 25 | 4 | if ($exception instanceof JsonRpcExceptionInterface) { |
|
| 26 | 1 | return $exception; |
|
| 27 | } |
||
| 28 | 3 | $errorCode = (int) $exception->getCode(); |
|
| 29 | 3 | if ($errorCode < self::MIN_VALID_ERROR_CODE || $errorCode > self::MAX_VALID_ERROR_CODE) { |
|
| 30 | 1 | return new JsonRpcInternalErrorException($exception); |
|
| 31 | } |
||
| 32 | |||
| 33 | 2 | $data = []; |
|
| 34 | |||
| 35 | 2 | if ($exception->getPrevious()) { |
|
| 36 | 1 | $data[self::ERROR_DATA_PREVIOUS_KEY] = $exception->getPrevious()->getMessage(); |
|
| 37 | } |
||
| 38 | |||
| 39 | 2 | return new JsonRpcException($errorCode, $exception->getMessage(), $data); |
|
| 40 | } |
||
| 42 |