Private_drive_model   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 127
Duplicated Lines 54.33 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 69
loc 127
rs 10
c 0
b 0
f 0
wmc 14
lcom 0
cbo 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A create() 0 15 1
A get_pending() 0 5 1
A get_all() 0 4 1
A check_status() 0 5 1
A match_id_user() 0 5 1
A get_email_username() 7 7 1
A get_request() 0 5 1
A get_email_approver() 7 7 1
A cancel() 11 11 1
A fh_reject() 10 10 1
A fh_approve() 11 11 1
A cs_reject() 11 11 1
A cs_approve() 12 12 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 Private_drive_model extends CI_Model {
4
5
    public function __construct() {
6
        parent::__construct();
7
    }
8
9
    public function create($requester, $user, $user_un, $path, $access, $approver) {
10
        
11
        $data = array(
12
            'requester' => $_SESSION['ldap']['full_name'],
13
            'requester_un' => $_SESSION['username'],
14
            'requested_at' => date("Y-m-d H:i:s", time()),
15
            'user' => $this->input->post('user'),
16
            'user_un' => $user_un,
17
            'path' => $this->input->post('path'),
18
            'access' => $this->input->post('access'),
19
            'approver' => $this->input->post('approver'),
20
        );
21
22
        return $this->db->insert('private_drive', $data);
23
    }
24
    
25
    public function get_pending() {
26
        $this->db->where('status', '0')->or_where('status', '1');
27
        $query = $this->db->get('private_drive');
28
        return $query->result_array();
29
    }
30
    
31
    public function get_all() {
32
        $query = $this->db->get('private_drive');
33
        return $query->result_array();
34
    }
35
    
36
    public function check_status() {
37
        $this->db->where('requester_un', $_SESSION['username'])->or_where('user_un', $_SESSION['username'])->or_where('approver', $_SESSION['ldap']['full_name']);
38
        $query = $this->db->get('private_drive');
39
        return $query->result_array();
40
    }
41
    
42
    public function match_id_user($id) {
43
        $this->db->where('id', $id);
44
        $query = $this->db->get('private_drive');
45
        return $query->result_array();
46
    }
47
    
48 View Code Duplication
    public function get_email_username($username) {        
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...
49
        
50
        $this->db->select('email');
51
        $this->db->from('users_ad');
52
        $this->db->where('username', $username);
53
        return $this->db->get()->row('email');
54
    }
55
    
56
    public function get_request($id) {
57
        $this->db->where('id', $id);
58
        $query = $this->db->get('private_drive');
59
        return $query->result_array();
60
    }
61
    
62 View Code Duplication
    public function get_email_approver($full_name) {        
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...
63
        
64
        $this->db->select('email');
65
        $this->db->from('users_ad');
66
        $this->db->where('full_name', $full_name);
67
        return $this->db->get()->row('email');
68
    }
69
    
70 View Code Duplication
    public function cancel($id) {
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...
71
            
72
        $this->db->where('id', $id);
73
	$this->db->from('private_drive');
74
        $data = array(
75
            'status' => '5',
76
            'canceled_by' => $_SESSION['ldap']['full_name'],
77
            'canceled_at' => date("Y-m-d H:i:s", time()),
78
        );
79
        return $this->db->update('private_drive', $data);
80
    }
81
    
82 View Code Duplication
    public function fh_reject($id) {
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...
83
            
84
        $this->db->where('id', $id);
85
	$this->db->from('private_drive');
86
        $data = array(
87
            'status' => '3',
88
            'approved_at' => date("Y-m-d H:i:s", time()),
89
        );
90
        return $this->db->update('private_drive', $data);
91
    }
92
    
93 View Code Duplication
    public function fh_approve($id) {
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...
94
            
95
        $this->db->where('id', $id);
96
	$this->db->from('private_drive');
97
        $data = array(
98
            'status' => '1',
99
            'approved_at' => date("Y-m-d H:i:s", time()),
100
        );
101
        
102
        return $this->db->update('private_drive', $data);
103
    }
104
    
105 View Code Duplication
    public function cs_reject($id) {
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...
106
            
107
        $this->db->where('id', $id);
108
	$this->db->from('private_drive');
109
        $data = array(
110
            'status' => '4',
111
            'actioned_at' => date("Y-m-d H:i:s", time()),
112
            'actioned_by' => $_SESSION['ldap']['full_name'],
113
        );
114
        return $this->db->update('private_drive', $data);
115
    }
116
    
117 View Code Duplication
    public function cs_approve($id) {
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...
118
            
119
        $this->db->where('id', $id);
120
	$this->db->from('private_drive');
121
        $data = array(
122
            'status' => '2',
123
            'actioned_at' => date("Y-m-d H:i:s", time()),
124
            'actioned_by' => $_SESSION['ldap']['full_name'],
125
        );
126
        
127
        return $this->db->update('private_drive', $data);
128
    }
129
}