Completed
Pull Request — master (#1)
by one
09:53
created

ApiException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
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
    public function __construct(string $message, int $code, array $data = [])
38
    {
39
        parent::__construct($message, $code);
40
41
        $this->type = ApiErrorEnumType::GENERAL_ERROR;
42
        $this->data = $data;
43
    }
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
    public function getData(): array
59
    {
60
        return $this->data;
61
    }
62
}
63