Status::create()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 49
Code Lines 31

Duplication

Lines 21
Ratio 42.86 %

Importance

Changes 0
Metric Value
cc 4
eloc 31
nc 4
nop 0
dl 21
loc 49
rs 8.7972
c 0
b 0
f 0
1
<?php defined('BASEPATH') OR exit('No direct script access allowed');
2
3
class Status extends My_Public {
4
5
    public function __construct() {
6
        parent::__construct();
7
        $this->load->model('computing-support/status_model', 'status_model');
8
    }
9
10 View Code Duplication
    public function index() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
12
        $data = array();
13
        $data['status'] = $this->status_model->view();
14
15
        $this->load->view('templates/header', $data);
16
        $this->load->view('computing-support/status/view');
17
        $this->load->view('templates/footer');
18
    }
19
20 View Code Duplication
    public function display() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
22
        $data = array();
23
        $data['status'] = $this->status_model->view();
24
25
        $this->load->view('templates/header', $data);
26
        $this->load->view('computing-support/status/display');
27
        $this->load->view('templates/footer');
28
    }
29
30
    public function auto() {
31
32
        $data = array();
33
        $data['status'] = $this->status_model->auto();
34
        $this->load->view('computing-support/status/auto', $data);
35
    }
36
37 View Code Duplication
    public function reset() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
39
        if (in_array('CN=Dashboard_Admin,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) {
40
41
            if (isset($_GET['sid'])) {
42
43
                $sid = $_GET['sid'];
44
                $this->status_model->reset($sid);
45
                
46
                $function = 'reset_status_monitor_'.$sid;
47
                $this->user_model->function_log($function);
48
49
                redirect($_SERVER['HTTP_REFERER']);
50
            }
51
52
            redirect($_SERVER['HTTP_REFERER']);
53
        } else {
54
            redirect($_SERVER['HTTP_REFERER']);
55
        }
56
    }
57
58 View Code Duplication
    public function delete() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
60
        if (in_array('CN=Dashboard_Admin,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) {
61
62
            if (isset($_GET['sid'])) {
63
64
                $sid = $_GET['sid'];
65
                $this->status_model->delete($sid);
66
                
67
                $function = 'delete_status_monitor_'.$sid;
68
                $this->user_model->function_log($function);
69
70
                redirect('computing-support/status');
71
            }
72
73
            redirect($_SERVER['HTTP_REFERER']);
74
        } else {
75
            redirect($_SERVER['HTTP_REFERER']);
76
        }
77
    }
78
79
    public function edit() {
80
81
        if (in_array('CN=Dashboard_Admin,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups']) ||
82
                in_array('CN=DG06,OU=Distribution Groups,OU=Email Groups,OU=Accounts,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) {
83
84
            if (isset($_GET['sid'])) {
85
                $sid = $_GET['sid'];
86
                
87
                $data = array();
88
                $data['get_current'] = $this->status_model->edit_get($sid);
89
            }
90
            $this->load->helper('form');
91
            $this->load->library('form_validation');
92
93
            // validation rules
94
            $this->form_validation->set_rules('name', 'Service name', 'trim|required|min_length[3]');
95
            $this->form_validation->set_rules('icon', 'Icon', 'trim|required|min_length[4]');
96
97
            if ($this->form_validation->run() === false) {
98
99
                $this->load->view('templates/header');
100
                $this->load->view('computing-support/status/edit', $data);
0 ignored issues
show
Bug introduced by
The variable $data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
101
                $this->load->view('templates/footer');
102
            } else {
103
104
                $id = $this->input->post('id');
105
                $name = $this->input->post('name');
106
                $icon = $this->input->post('icon');
107
                $url = $this->input->post('url');
108
                $comment = $this->input->post('comment');
109
                $category = $this->input->post('category');
110
                $status = $this->input->post('status');
111
                $username = $_SESSION['username'];
112
113
                if ($this->status_model->edit_update($id, $name, $icon, $url, $comment, $category, $status, $username)) {
114
                    
115
                    $function = 'edit_status_monitor_'.$sid;
0 ignored issues
show
Bug introduced by
The variable $sid does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
116
                    $this->user_model->function_log($function);
117
118
                    $this->load->view('templates/header');
119
                    $this->load->view('computing-support/status/updated');
120
                    $this->load->view('templates/footer');
121
                } else {
122
                    
123
                    $function = 'edit_status_monitor_error_'.$sid;
124
                    $this->user_model->function_log($function);
125
126
                    $data = new stdClass();
127
                    $data->error = 'There was a problem editing this service. Please try again.';
128
129
                    // failed to create user
130
                    $this->load->view('templates/header');
131
                    $this->load->view('computing-support/status/edit', $data);
132
                    $this->load->view('templates/footer');
133
                }
134
            }
135
        }
136
    }
137
138
    public function create() {
139
140
        if (in_array('CN=Dashboard_Admin,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) {
141
142
            $this->load->helper('form');
143
            $this->load->library('form_validation');
144
145
            // validation rules
146
            $this->form_validation->set_rules('name', 'Service name', 'trim|required|min_length[3]');
147
            $this->form_validation->set_rules('icon', 'Icon', 'trim|required|min_length[4]');
148
149
            if ($this->form_validation->run() === false) {
150
151
                $this->load->view('templates/header');
152
                $this->load->view('computing-support/status/edit');
153
                $this->load->view('templates/footer');
154
            } else {
155
156
                $name = $this->input->post('name');
157
                $icon = $this->input->post('icon');
158
                $url = $this->input->post('url');
159
                $category = $this->input->post('category');
160
                $status = $this->input->post('status');
161
                $username = $_SESSION['username'];
162
163 View Code Duplication
                if ($this->status_model->create($name, $icon, $url, $category, $status, $username)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
164
                    
165
                    $function = 'create_status_monitor_'.$sid;
0 ignored issues
show
Bug introduced by
The variable $sid does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
166
                    $this->user_model->function_log($function);
167
168
                    $this->load->view('templates/header');
169
                    $this->load->view('computing-support/status/created');
170
                    $this->load->view('templates/footer');
171
                } else {
172
                    
173
                    $function = 'create_status_monitor_error_'.$sid;
174
                    $this->user_model->function_log($function);
175
176
                    $data = new stdClass();
177
                    $data->error = 'There was a problem editing this service. Please try again.';
178
179
                    // failed to create user
180
                    $this->load->view('templates/header');
181
                    $this->load->view('computing-support/status/edit', $data);
182
                    $this->load->view('templates/footer');
183
                }
184
            }
185
        }
186
    }
187
188
}
189
190
// END controller
191