Completed
Pull Request — master (#2)
by Sergey
03:47
created

InvalidRequestException::__construct()   A

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
eloc 9
c 0
b 0
f 0
dl 0
loc 18
ccs 0
cts 10
cp 0
rs 9.9666
cc 4
nc 3
nop 4
crap 20
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
    /** @var mixed[] */
24
    protected $data;
25
26
    /**
27
     * InternalErrorException constructor.
28
     * @param string $message
29
     * @param int $code
30
     * @param Throwable|null $previous
31
     * @param mixed[]|null $data
32
     */
33
    public function __construct(
34
        string $message = "",
35
        int $code = 0,
36
        Throwable $previous = null,
37
        array $data = null
38
    ) {
39
        if ($previous !== null && $data === null) {
40
            $this->data = [
41
                'exception' => get_class($previous),
42
                'code'      => $previous->getCode(),
43
                'file'      => $previous->getFile(),
44
                'line'      => $previous->getLine(),
45
            ];
46
        } elseif ($data !== null) {
47
            $this->data = $data;
48
        }
49
50
        parent::__construct($message, $code, $previous);
51
    }
52
53
    /**
54
     * @return mixed[]|null
55
     */
56
    public function getData(): ?array
57
    {
58
        return $this->data;
59
    }
60
}
61