Completed
Push — master ( d0f0fb...030685 )
by Andreas
23:49
created

midcom_error_midgard   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 27
ccs 16
cts 18
cp 0.8889
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 20 6
A log() 0 3 1
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 32
    public function __construct(mgd_exception $e, $id)
20
    {
21 32
        if ($id !== null) {
22 32
            if ($e->getCode() === MGD_ERR_NOT_EXISTS) {
23 18
                $code = MIDCOM_ERRNOTFOUND;
24 18
                $message = "The object with identifier {$id} was not found.";
25 16
            } elseif ($e->getCode() == MGD_ERR_ACCESS_DENIED) {
26
                $code = MIDCOM_ERRFORBIDDEN;
27
                $message = midcom::get()->i18n->get_string('access denied', 'midcom');
28 16
            } elseif ($e->getCode() == MGD_ERR_OBJECT_DELETED) {
29 1
                $code = MIDCOM_ERRNOTFOUND;
30 1
                $message = "The object with identifier {$id} was deleted.";
31
            }
32
        }
33
        //If other options fail, go for the server error
34 32
        if (!isset($code)) {
35 15
            $code = MIDCOM_ERRCRIT;
36 15
            $message = $e->getMessage();
37
        }
38 32
        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 32
    }
40
41 20
    public function log($loglevel = MIDCOM_LOG_WARN)
42
    {
43 20
        parent::log($loglevel);
44
    }
45
}