Ownership_model   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 100
Duplicated Lines 44 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 44
loc 100
rs 10
c 0
b 0
f 0
wmc 11
lcom 0
cbo 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A create() 14 14 1
A get_all_ownership() 0 4 1
A get_pending_ownership() 0 5 1
A check_ownership() 0 5 1
A match_id_user() 0 6 1
A email_id() 6 6 1
A approve() 12 12 1
A reject() 12 12 1
A cancel() 0 10 1
A terms() 0 11 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 Ownership_model extends CI_Model {
4
5
    public function __construct() {
6
    }
7
8 View Code Duplication
    public function create($logged, $staff_full, $make, $model, $sn) {
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...
9
        
10
        $data = array(
11
            'logged' => $this->input->post('logged'),
12
            'logged_at' => date("Y-m-d H:i:s", time()),
13
            'staff_full' => $this->input->post('staff_full'),
14
            'make' => $this->input->post('make'),
15
            'model' => $this->input->post('model'),
16
            'sn' => $this->input->post('sn'),
17
        );
18
        
19
        return $this->db->insert('ownership', $data);
20
        
21
    }
22
    
23
    public function get_all_ownership() {
24
        $query = $this->db->get('ownership');
25
        return $query->result_array();
26
    }
27
    
28
    public function get_pending_ownership() {
29
        $this->db->where('status', '0')->or_where('status', '1');
30
        $query = $this->db->get('ownership');
31
        return $query->result_array();
32
    }
33
    
34
    public function check_ownership() {
35
        $this->db->where('staff_full', $_SESSION['ldap']['full_name']);
36
        $query = $this->db->get('ownership');
37
        return $query->result_array();
38
    }
39
    
40
    public function match_id_user($id) {
41
        $this->db->select('staff_full');
42
        $this->db->where('id', $id);
43
        $query = $this->db->get('ownership');
44
        return $query->result_array();
45
    }
46
    
47 View Code Duplication
    public function email_id($staff_full) {
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...
48
        $this->db->select('email');
49
        $this->db->where('full_name', $staff_full);
50
        $query = $this->db->get('users_ad');
51
        return $query->result_array();
52
    }
53
    
54 View Code Duplication
    public function 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...
55
            
56
        $this->db->where('id', $id);
57
	$this->db->from('ownership');
58
        $data = array(
59
            'status' => '3',
60
            'transfer' => date("Y-m-d H:i:s", time()),
61
            'transfer_by' => $_SESSION['ldap']['full_name'],
62
        );
63
        return $this->db->update('ownership', $data);
64
        
65
    }
66
    
67 View Code Duplication
    public function 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...
68
            
69
        $this->db->where('id', $id);
70
	$this->db->from('ownership');
71
        $data = array(
72
            'status' => '2',
73
            'transfer' => date("Y-m-d H:i:s", time()),
74
            'transfer_by' => $_SESSION['ldap']['full_name'],
75
        );
76
        return $this->db->update('ownership', $data);
77
        
78
    }
79
    
80
    public function cancel($id) {
81
            
82
        $this->db->where('id', $id);
83
	$this->db->from('ownership');
84
        $data = array(
85
            'status' => '4',
86
        );
87
        return $this->db->update('ownership', $data);
88
        
89
    }
90
    
91
    public function terms($id) {
92
            
93
        $this->db->where('id', $id);
94
	$this->db->from('ownership');
95
        $data = array(
96
            'status' => '1',
97
            'policy_accepted' => date("Y-m-d H:i:s", time()),
98
        );
99
        return $this->db->update('ownership', $data);
100
        
101
    }
102
}
103
?>
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...
104
105
106