Visitor   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 104
Duplicated Lines 18.27 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 14
lcom 0
cbo 1
dl 19
loc 104
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B index() 19 60 7
A history() 0 21 3
A reset() 0 12 3

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
2
3
defined('BASEPATH') OR exit('No direct script access allowed');
4
5
class Visitor extends My_Public {
6
7
    public function __construct() {
8
        parent::__construct();
9
        $this->load->library('grocery_CRUD');
10
        $this->load->model('marketing/visitor_model', 'visitor_model');
11
    }
12
13
    public function index() {
14
15
        if (isset($_COOKIE['CI_PASSKEY']) === TRUE && in_array('visitor', unserialize($_COOKIE['CI_PASSKEY'])) ||
16
                in_array('CN=Intranet_Edit_Marketing,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups']) ||
17
                in_array('CN=Dashboard_Admin,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['dashboard_groups'])) {
18
19
            $this->load->helper('form');
20
            $this->load->library('form_validation');
21
22
            // validation rules
23
            $this->form_validation->set_rules('first_name', 'First Name', 'trim|required|min_length[2]');
24
            $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required|min_length[2]');
25
            $this->form_validation->set_rules('dob_d', 'Date of Birth Day', 'trim|required|numeric|min_length[2]');
26
            $this->form_validation->set_rules('dob_m', 'Date of Birth Month', 'trim|required|numeric|min_length[2]');
27
            $this->form_validation->set_rules('dob_y', 'Date of Birth Year', 'trim|required|numeric|min_length[4]');
28
29
            if ($this->form_validation->run() === false) {
30
31
                $this->load->view('templates/header');
32
                $this->load->view('marketing/visitor/view');
33
                $this->load->view('templates/footer');
34
            } else {
35
36
                $first_name = $this->input->post('first_name');
37
                $last_name = $this->input->post('last_name');
38
                $email = $this->input->post('email');
39
                $postcode = $this->input->post('postcode');
40
                $dob = $this->input->post('dob_d') . '/' . $this->input->post('dob_m') . '/' . $this->input->post('dob_y');
41
                $current = $this->input->post('current');
42
                $current_other = $this->input->post('current_other');
43
                $subject = $this->input->post('subject');
44
                $hear = $this->input->post('hear');
45
                $year = $this->input->post('year');
46
47 View Code Duplication
                if ($this->visitor_model->post($first_name, $last_name, $email, $postcode, $dob, $current, $current_other, $subject, $hear, $year)) {
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...
48
49
                    // user created
50
                    $this->load->view('templates/header');
51
                    $this->load->view('marketing/visitor/complete');
52
                    $this->load->view('templates/footer');
53
                } else {
54
                    
55
                    $function = 'ERROR_visitor_form_submition';
56
                    $this->user_model->function_log($function);
57
58
                    $data = new stdClass();
59
                    $data->error = 'There was a problem submitting this form. Please try again.';
60
61
                    // failed to create user
62
                    $this->load->view('templates/header');
63
                    $this->load->view('marketing/visitor/view', $data);
64
                    $this->load->view('templates/footer');
65
                }
66
            }
67
        } else {
68
69
            $this->session->set_userdata('last_url', current_url());
70
            redirect('authentication/passkey?id=visitor');
71
        }
72
    }
73
74
    public function history() {
75
76
        if (in_array('CN=Dashboard_Admin,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups']) ||
77
                in_array('CN=Intranet_Edit_Marketing,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) {
78
79
            $crud = new grocery_CRUD();
80
            $crud->set_table('visitor');
81
            $crud->set_subject('visitor', 'Visitor - Open Day');
82
            $crud->unset_columns('id');
83
            $crud->unset_add();
84
            $crud->unset_read();
85
            $output = $crud->render();
86
87
            $this->load->view('templates/header.php');
88
            $this->load->view('marketing/visitor/history', $output);
89
            $this->load->view('templates/footer.php');
90
            $this->load->view('templates/table_assets.php', $output);
91
        } else {
92
            redirect('permissions');
93
        }
94
    }
95
96
    public function reset() {
97
        
98
        if (in_array('CN=Dashboard_Admin,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups']) ||
99
                in_array('CN=Intranet_Edit_Marketing,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) {
100
101
            $this->db->empty_table('visitor');
102
            redirect($_SERVER['HTTP_REFERER']);
103
            
104
            $function = 'visitor_form_RESET';
105
            $this->user_model->function_log($function);
106
        }
107
    }
108
}