Completed
Push — master ( 9d10c2...bf46e5 )
by Lars
05:14
created

ModuleMaintenance   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 84.09%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 13
c 1
b 1
f 0
lcom 1
cbo 2
dl 0
loc 80
rs 10
ccs 37
cts 44
cp 0.8409

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
A factory() 0 5 1
B load() 0 30 6
A registerModule() 0 5 1
A register() 0 5 1
A get() 0 8 2
1
<?php
2
/**
3
 * // @todo could probably extend ModuleHandler, and therefore not need the
4
 *          constant pointing to the modules.
5
@package Intraface_IntranetMaintenance
6
 */
7
class ModuleMaintenance
8
{
9
    private $id;
10
    private $db;
11
    private $value;
12
    public $error;
13
    private $sub_access;
14
15 22
    public function __construct($id = 0)
16
    {
17 22
        $this->id = intval($id);
18 22
        $this->db = MDB2::singleton(DB_DSN);
19 22
        if (PEAR::isError($this->db)) {
20
            throw new Exception("Error in creating db: ".$this->db->getUserInfo());
21
        }
22
23 22
        $this->error = new Intraface_Error;
24 22
        $this->value = array();
25
26 22
        $this->load();
27 22
    }
28
29 1
    static function factory($name)
30
    {
31 1
        $gateway = new Intraface_ModuleGateway(MDB2::singleton(DB_DSN));
32 1
        return $gateway->findByName($name);
33
    }
34
35 22
    private function load()
36
    {
37
        // Starter med at nustille
38 22
        $this->value = array();
39 22
        $this->sub_access;
40 22
        if ($this->id != 0) {
41 1
            $result = $this->db->query("SELECT * FROM module WHERE id = ".$this->id);
42 1
            if (PEAR::isError($result)) {
43
                throw new Exception("Error in query: ".$result->getUserInfo());
44
            }
45
46 1
            if ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
47 1
                $this->value = $row;
48
49
                // $this->sub_access = new SubAccessMaintenance($this);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50
51 1
                $j = 0;
0 ignored issues
show
Unused Code introduced by
$j is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
52 1
                $result_sub_access = $this->db->query("SELECT id, name, description FROM module_sub_access WHERE active = 1 AND module_id = ".$row["id"]." ORDER BY description");
53 1
                if (PEAR::isError($result_sub_access)) {
54
                    throw new Exception("Error in query: ".$result_sub_access->getUserInfo());
55
                }
56 1
                $i = 0;
57 1
                $this->value["sub_access"] = array();
58 1
                while ($row = $result_sub_access->fetchRow(MDB2_FETCHMODE_ASSOC)) {
59 1
                    $this->value["sub_access"][$i] = $row;
60 1
                    $i++;
61 1
                }
62 1
            }
63 1
        }
64 22
    }
65
66 1
    public function registerModule($module_name)
67
    {
68 1
        $gateway = new Intraface_ModuleGateway(MDB2::singleton(DB_DSN));
69 1
        return $gateway->registerByName($module_name);
70
    }
71
72 19
    public function register()
73
    {
74 19
        $gateway = new Intraface_ModuleGateway(MDB2::singleton(DB_DSN));
75 19
        return $gateway->registerAll();
76
    }
77
78
    public function get($key = '')
79
    {
80
        if (!empty($key)) {
81
            return($this->value[$key]);
82
        } else {
83
            return $this->value;
84
        }
85
    }
86
}
87