Error   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 86.36%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 60
ccs 19
cts 22
cp 0.8636
rs 10
c 0
b 0
f 0
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getFirst() 0 3 1
A getLast() 0 3 1
A instance() 0 4 2
A getAll() 0 3 1
A create() 0 15 2
A burst() 0 5 1
1
<?php
2
3
namespace MocOrm\Model;
4
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
        $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()
56
    {
57 1
        return current($this->errors);
58
    }
59
60
    private function burst($message, $code, $type)
61
    {
62
//        if(!array_search($type, ERRORS)) throw new \InvalidArgumentException('Type of burst not found.');
63
        $type = '\\' . $type;
64
        throw new $type($message, $code);
65
    }
66
}