Address_book_model   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 67
Duplicated Lines 40.3 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 27
loc 67
rs 10
c 0
b 0
f 0
wmc 11
lcom 0
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A change() 0 16 1
A get_faculty() 13 13 3
A get_department() 14 14 4
A get_faculty_from_number() 0 7 1
A get_department_from_number() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php defined('BASEPATH') OR exit('No direct script access allowed');
2
3
class Address_book_model extends CI_Model {
4
5
    public function __construct() {
6
    }
7
8
    public function change($faculty, $department, $name, $room, $phone, $position) {
9
        
10
        $data = array(
11
            'requested' => date("Y-m-d H:i:s", time()),
12
            'by' => $_SESSION['ldap']['full_name'],
13
            'new_faculty' => $faculty[0]['faculty'],
14
            'new_department' => $department[0]['subfaculty'],
15
            'new_name' => $this->input->post('name'),
16
            'new_room' => $this->input->post('room'),
17
            'new_phone' => $this->input->post('phone'),
18
            'new_position' => $this->input->post('position'),
19
        );
20
        
21
        return $this->db->insert('address_book', $data);
22
        
23
    }
24
    
25 View Code Duplication
    function get_faculty() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
26
        $this->db->from('faculty');
27
        $this->db->order_by('faculty');
28
        $result = $this->db->get();
29
        $return = array();
30
        if ($result->num_rows() > 0) {
31
            foreach ($result->result_array() as $row) {
32
                $return[$row['cat_id']] = $row['faculty'];
33
            }
34
        }
35
36
        return $return;
37
    }
38
39 View Code Duplication
    function get_department() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
40
        if (!isset($_GET['cat'])) {
41
            $_GET['cat'] = '1';
42
        }
43
        $result = $this->db->get_where('facultysub', array('cat_id' => $_GET['cat']));
44
        $return = array();
45
        if ($result->num_rows() > 0) {
46
            foreach ($result->result_array() as $row) {
47
                $return[$row['cat_key']] = $row['subfaculty'];
48
            }
49
        }
50
51
        return $return;
52
    }
53
    
54
    function get_faculty_from_number($faculty) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
55
        
56
        $this->db->select('faculty');
57
        $this->db->where('cat_id', $faculty);
58
	$this->db->from('faculty');
59
        return $this->db->get()->result_array();
60
    }
61
    
62
    function get_department_from_number($department) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
63
        
64
        $this->db->select('subfaculty');
65
        $this->db->where('cat_key', $department);
66
	$this->db->from('facultysub');
67
        return $this->db->get()->result_array();
68
    }
69
}
70
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
71
72
73