| Total Complexity | 9 |
| Total Lines | 58 |
| 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() |
|
| 18 | { |
||
| 19 | 1 | return $this; |
|
| 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 | 2 | $errors['message'] = $message; |
|
|
|
|||
| 29 | 2 | $errors['code'] = $code; |
|
| 30 | 2 | $errors['type'] = $type; |
|
| 31 | |||
| 32 | 2 | $instance->errors[] = $errors; |
|
| 33 | |||
| 34 | 2 | return $instance; |
|
| 35 | } |
||
| 36 | |||
| 37 | 2 | public static function instance() |
|
| 38 | { |
||
| 39 | 2 | if (!self::$_instance) self::$_instance = new self(); |
|
| 40 | 2 | return self::$_instance; |
|
| 41 | } |
||
| 42 | |||
| 43 | 1 | public function getAll() |
|
| 44 | { |
||
| 45 | 1 | return $this->errors; |
|
| 46 | } |
||
| 47 | |||
| 48 | 1 | public function getLast() |
|
| 49 | { |
||
| 50 | 1 | return end($this->errors); |
|
| 51 | } |
||
| 52 | |||
| 53 | 1 | public function getFirst() |
|
| 56 | } |
||
| 57 | |||
| 58 | private function burst($message, $code, $type) |
||
| 59 | { |
||
| 60 | // if(!array_search($type, ERRORS)) throw new \InvalidArgumentException('Type of burst not found.'); |
||
| 63 | } |
||
| 64 | } |