Completed
Pull Request — master (#38)
by Thomas
02:53
created

Error   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 51
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 3
A addParams() 0 4 1
A getMessage() 0 4 1
A getCode() 0 4 1
1
<?php
2
3
namespace ORM\Dbal;
4
5
use ORM\Dbal\Column;
6
use ORM\EntityManager;
7
use ORM\Namer;
8
9
class Error
10
{
11
    const ERROR_CODE = 'UNKNOWN';
12
13
    /** @var string[] */
14
    protected $params = [
15
        'code' => self::ERROR_CODE
16
    ];
17
18
    /** @var string */
19
    protected $message = 'ERROR(%code%) occurred';
20
21
    /**
22
     * Error constructor.
23
     * @param array $params
24
     * @param null $code
25
     * @param null $message
26
     */
27 38
    public function __construct(array $params = [], $code = null, $message = null)
28
    {
29
        // set code from concrete class
30 38
        $this->params['code'] = static::ERROR_CODE;
31
32
        // overwrite message from params
33 38
        if ($message) {
34 1
            $this->message = $message;
35
        }
36
37
        // overwrite code from params
38 38
        if ($code) {
39 1
            $this->params['code'] = $code;
40
        }
41
42 38
        $this->addParams($params);
43 38
    }
44
45 38
    public function addParams($params)
46
    {
47 38
        $this->params = array_merge($this->params, $params);
48 38
    }
49
50 37
    public function getMessage()
51
    {
52 37
        return EntityManager::getInstance()->getNamer()->substitute($this->message, $this->params);
53
    }
54
55 1
    public function getCode()
56
    {
57 1
        return $this->params['code'];
58
    }
59
}
60