Passed
Branch feature-validator (55f4e3)
by Thomas
03:27
created

Error::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 4
nop 2
crap 3
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 null $code
24
     * @param null $message
25
     */
26 19
    public function __construct($code = null, $message = null)
27
    {
28
        // set code from concrete class
29 19
        $this->params['code'] = static::ERROR_CODE;
30
31
        // overwrite message from params
32 19
        if ($message) {
33 16
            $this->message = $message;
34
        }
35
36
        // overwrite code from params
37 19
        if ($code) {
38 17
            $this->params['code'] = $code;
39
        }
40 19
    }
41
42 16
    public function addParams($params)
43
    {
44 16
        $this->params = array_merge($this->params, $params);
45 16
    }
46
47 18
    public function getMessage()
48
    {
49 18
        return EntityManager::getInstance()->getNamer()->substitute($this->message, $this->params);
50
    }
51
52 1
    public function getCode()
53
    {
54 1
        return $this->params['code'];
55
    }
56
}
57