ApiException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
/*
4
 * (c) Lukasz D. Tulikowski <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace App\Exception;
13
14
use App\Exception\Enum\ApiErrorEnumType;
15
use Exception;
16
17
class ApiException extends Exception
18
{
19
    public const DEFAULT_MESSAGE = 'General error.';
20
21
    /**
22
     * @var string
23
     */
24
    protected $type;
25
26
    /**
27
     * @var array
28
     */
29
    protected $data;
30
31
    /**
32
     * {@inheritdoc}
33
     *
34
     * @param string $message
35
     * @param array $data
36
     */
37 4
    public function __construct(string $message, int $code, array $data = [])
38
    {
39 4
        parent::__construct($message, $code);
40
41 4
        $this->type = ApiErrorEnumType::GENERAL_ERROR;
42 4
        $this->data = $data;
43 4
    }
44
45
    /**
46
     * @param array $data
47
     *
48
     * @return ApiException
49
     */
50
    public static function createWithData(array $data = []): self
51
    {
52
        return new static(static::DEFAULT_MESSAGE, 0, $data);
53
    }
54
55
    /**
56
     * @return array
57
     */
58 3
    public function getData(): array
59
    {
60 3
        return $this->data;
61
    }
62
}
63