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

midcom_error_midgard::__construct()   A

Complexity

Conditions 6
Paths 10

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 6.0852

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 14
c 1
b 0
f 0
nc 10
nop 2
dl 0
loc 20
ccs 13
cts 15
cp 0.8667
crap 6.0852
rs 9.2222
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
}