InvalidParamsException::getData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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