Test Failed
Pull Request — master (#2)
by Sergey
04:44 queued 12s
created

InternalErrorException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 3 1
A __construct() 0 18 4
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 InternalErrorException
18
 *
19
 * @package Onnov\JsonRpcServer\Exception
20
 */
21
class InternalErrorException 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