Completed
Branch release/0.1.0 (dcda87)
by Yo
03:15 queued 01:20
created

JsonRpcParseErrorException::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 4
nop 3
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Yoanm\JsonRpcServer\Domain\Exception;
3
4
/**
5
 * Class JsonRpcParseErrorException
6
 */
7
class JsonRpcParseErrorException extends JsonRpcException
8
{
9
    const CODE = -32700;
10
11
    const DATA_CONTENT_KEY = 'content';
12
    const DATA_ERROR_KEY = 'error';
13
    const DATA_ERROR_CODE_KEY = 'code';
14
    const DATA_ERROR_MESSAGE_KEY = 'message';
15
16
    /**
17
     * @param string $content
18
     * @param mixed  $parseErrorCode
19
     * @param mixed  $parseErrorMessage
20
     */
21 4
    public function __construct(string $content, $parseErrorCode = null, $parseErrorMessage = null)
22
    {
23
        $data = [
24 4
            self::DATA_CONTENT_KEY => $content,
25
        ];
26 4
        if ($parseErrorCode) {
27 2
            $data[self::DATA_ERROR_KEY][self::DATA_ERROR_CODE_KEY] = $parseErrorCode;
28
        }
29 4
        if ($parseErrorMessage) {
30 1
            $data[self::DATA_ERROR_KEY][self::DATA_ERROR_MESSAGE_KEY] = $parseErrorMessage;
31
        }
32
33 4
        parent::__construct(self::CODE, 'Parse error', $data);
34 4
    }
35
}
36