Passed
Push — master ( e63a9a...cfd6c6 )
by Andreas
25:20
created

midcom_error_midgard::log()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package midcom
4
 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
5
 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 */
8
9
10
use midgard\portable\api\error\exception as mgd_exception;
11
12
/**
13
 * MidCOM wrapped Midgard exception
14
 *
15
 * @package midcom
16
 */
17
class midcom_error_midgard extends midcom_error
18
{
19 31
    public function __construct(mgd_exception $e, $id)
20
    {
21 31
        if ($id !== null) {
22 31
            if ($e->getCode() === MGD_ERR_NOT_EXISTS) {
23 19
                $code = MIDCOM_ERRNOTFOUND;
24 19
                $message = "The object with identifier {$id} was not found.";
25 14
            } elseif ($e->getCode() == MGD_ERR_ACCESS_DENIED) {
26
                $code = MIDCOM_ERRFORBIDDEN;
27
                $message = midcom::get()->i18n->get_string('access denied', 'midcom');
28 14
            } elseif ($e->getCode() == MGD_ERR_OBJECT_DELETED) {
29
                $code = MIDCOM_ERRNOTFOUND;
30
                $message = "The object with identifier {$id} was deleted.";
31
            }
32
        }
33
        //If other options fail, go for the server error
34 31
        if (!isset($code)) {
35 14
            $code = MIDCOM_ERRCRIT;
36 14
            $message = $e->getMessage();
37
        }
38 31
        parent::__construct($message, $code);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $message does not seem to be defined for all execution paths leading up to this point.
Loading history...
39 31
    }
40
41 21
    public function log(int $loglevel = MIDCOM_LOG_WARN)
42
    {
43 21
        parent::log($loglevel);
44
    }
45
}