InvalidParamsException::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 6.5971

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 3
nop 4
dl 0
loc 18
ccs 5
cts 11
cp 0.4545
crap 6.5971
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 InvalidParamsException
18
 *
19
 * @package Onnov\JsonRpcServer\Exception
20
 */
21
class InvalidParamsException extends RuntimeException
22
{
23
    /**
24
     * @var mixed[]|null
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 2
    public function __construct(
37
        string $message = "",
38
        int $code = 0,
39
        Throwable $previous = null,
40
        array $data = null
41
    ) {
42 2
        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 2
        } elseif ($data !== null) {
50 2
            $this->data = $data;
51
        }
52
53 2
        parent::__construct($message, $code, $previous);
54
    }
55
56
    /**
57
     * @return mixed[]|null
58
     */
59 2
    public function getData(): ?array
60
    {
61 2
        return $this->data;
62
    }
63
}
64