Total Complexity | 9 |
Total Lines | 60 |
Duplicated Lines | 0 % |
Coverage | 86.36% |
Changes | 0 |
1 | <?php |
||
5 | class Error |
||
6 | { |
||
7 | private static $_instance; |
||
8 | |||
9 | const ACCEPTED_ERROR = [ |
||
10 | 'Exception', |
||
11 | 'InvalidArgumentException', |
||
12 | ]; |
||
13 | |||
14 | private $errors = []; |
||
15 | private $burst; |
||
16 | |||
17 | 1 | public function __construct() |
|
20 | } |
||
21 | |||
22 | 2 | public static function create($message, $code, $type = 'Exception') |
|
23 | { |
||
24 | 2 | $instance = self::instance(); |
|
25 | |||
26 | 2 | if ($instance->burst) $instance->burst($message, $code, $type); |
|
27 | |||
28 | $errors = [ |
||
29 | 2 | 'message' => $message, |
|
30 | 2 | 'code' => $code, |
|
31 | 2 | 'type' => $type |
|
32 | ]; |
||
33 | |||
34 | 2 | $instance->errors[] = $errors; |
|
35 | |||
36 | 2 | return $instance; |
|
37 | } |
||
38 | |||
39 | 2 | public static function instance() |
|
40 | { |
||
41 | 2 | if (!self::$_instance) self::$_instance = new self(); |
|
42 | 2 | return self::$_instance; |
|
43 | } |
||
44 | |||
45 | 1 | public function getAll() |
|
46 | { |
||
47 | 1 | return $this->errors; |
|
48 | } |
||
49 | |||
50 | 1 | public function getLast() |
|
51 | { |
||
52 | 1 | return end($this->errors); |
|
53 | } |
||
54 | |||
55 | 1 | public function getFirst() |
|
58 | } |
||
59 | |||
60 | private function burst($message, $code, $type) |
||
61 | { |
||
62 | // if(!array_search($type, ERRORS)) throw new \InvalidArgumentException('Type of burst not found.'); |
||
65 | } |
||
66 | } |