InvalidRequestException::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 9
c 0
b 0
f 0
nc 3
nop 4
dl 0
loc 18
ccs 0
cts 11
cp 0
crap 20
rs 9.9666
1
<?php
2
3
/**
4
 * Created by PhpStorm.
5
 * Project: json_rpc_server
6
 * User: sv
7
 * Date: 24.06.19
8
 * Time: 17:55
9
 */
10
11
namespace Onnov\JsonRpcServer\Exception;
12
13
use RuntimeException;
14
use Throwable;
15
16
/**
17
 * Class InvalidRequestException
18
 *
19
 * @package Onnov\JsonRpcServer\Exception
20
 */
21
class InvalidRequestException extends RuntimeException
22
{
23
    /**
24
     * @var mixed[]
25
     */
26
    protected $data;
27
28
    /**
29
     * InternalErrorException constructor.
30
     *
31
     * @param string         $message
32
     * @param int            $code
33
     * @param Throwable|null $previous
34
     * @param mixed[]|null   $data
35
     */
36
    public function __construct(
37
        string $message = "",
38
        int $code = 0,
39
        Throwable $previous = null,
40
        array $data = null
41
    ) {
42
        if ($previous !== null && $data === null) {
43
            $this->data = [
44
                'exception' => get_class($previous),
45
                'code'      => $previous->getCode(),
46
                'file'      => $previous->getFile(),
47
                'line'      => $previous->getLine(),
48
            ];
49
        } elseif ($data !== null) {
50
            $this->data = $data;
51
        }
52
53
        parent::__construct($message, $code, $previous);
54
    }
55
56
    /**
57
     * @return mixed[]|null
58
     */
59
    public function getData(): ?array
60
    {
61
        return $this->data;
62
    }
63
}
64