| Conditions | 8 |
| Paths | 8 |
| Total Lines | 79 |
| Code Lines | 47 |
| Lines | 30 |
| Ratio | 37.97 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php defined('BASEPATH') OR exit('No direct script access allowed'); |
||
| 64 | function __construct() { |
||
| 65 | parent::__construct(); |
||
| 66 | |||
| 67 | if (isset($_COOKIE['CI-CONCRETE5']) === FALSE) { |
||
| 68 | |||
| 69 | $this->session->set_userdata('last_url', current_url()); |
||
| 70 | redirect('http://'.$_SERVER['HTTP_HOST'].'/authentication/dashboard?url=' . current_url()); |
||
| 71 | } else { |
||
| 72 | |||
| 73 | $cookie = $_COOKIE['CI-CONCRETE5']; |
||
| 74 | $key = $this->config->item('concrete5authkey'); |
||
| 75 | $username = $this->user_model->decrypt($key, $cookie); |
||
| 76 | |||
| 77 | if ($this->user_model->user_exist($username) === FALSE) { |
||
| 78 | |||
| 79 | //expire fake cookie |
||
| 80 | setcookie('CI-CONCRETE5', 'expired', time() - (1), "/"); |
||
| 81 | $this->session->set_userdata('last_url', current_url()); |
||
| 82 | redirect('http://'.$_SERVER['HTTP_HOST'].'/authentication/dashboard?url=' . current_url()); |
||
| 83 | } else { |
||
| 84 | |||
| 85 | $user_ldap = $this->user_model->user_ldap($username); |
||
| 86 | |||
| 87 | if ($user_ldap['useraccountcontrol'] == '66050') { |
||
| 88 | // disabled, password never expire |
||
| 89 | redirect('http://'.$_SERVER['HTTP_HOST'].'/authentication/user-disabled'); |
||
| 90 | } elseif ($user_ldap['useraccountcontrol'] == '514') { |
||
| 91 | // disabled |
||
| 92 | redirect('http://'.$_SERVER['HTTP_HOST'].'/authentication/user-disabled'); |
||
| 93 | } else { |
||
| 94 | |||
| 95 | if (!in_array('CN=Staff,OU=Groups,DC=cant-col,DC=ac,DC=uk', $user_ldap['groups'])) { |
||
| 96 | |||
| 97 | redirect('http://'.$_SERVER['HTTP_HOST'].'/authentication/user-disabled'); |
||
| 98 | } else { |
||
| 99 | |||
| 100 | $ip = $_SERVER['REMOTE_ADDR']; |
||
| 101 | $is_private = $this->user_model->ip_is_private($ip); |
||
| 102 | if ($is_private === FALSE) { |
||
| 103 | |||
| 104 | if (isset($_SESSION['external_login']) === FALSE) { |
||
| 105 | |||
| 106 | $this->session->set_userdata('last_url', current_url()); |
||
| 107 | redirect('http://'.$_SERVER['HTTP_HOST'].'/dashboard/authentication/external-login'); |
||
| 108 | View Code Duplication | } else { |
|
| 109 | |||
| 110 | $uid = $this->user_model->get_uid_from_username($username); |
||
| 111 | $this->user_model->set_user($uid, $username, $ip); |
||
| 112 | $this->user_model->external_login_reset($uid); |
||
| 113 | // reset as internal |
||
| 114 | |||
| 115 | $this->session->set_userdata('username', $username); |
||
| 116 | $this->session->set_userdata('uid', $uid); |
||
| 117 | $this->session->set_userdata('ldap', $user_ldap); |
||
| 118 | $this->session->set_userdata('is_private', $is_private); |
||
| 119 | |||
| 120 | //uses sessions |
||
| 121 | $this->user_model->user_log(); |
||
| 122 | } |
||
| 123 | View Code Duplication | } else { |
|
| 124 | |||
| 125 | $uid = $this->user_model->get_uid_from_username($username); |
||
| 126 | $this->user_model->set_user($uid, $username, $ip); |
||
| 127 | $this->user_model->external_login_reset($uid); |
||
| 128 | // reset as internal |
||
| 129 | |||
| 130 | $this->session->set_userdata('username', $username); |
||
| 131 | $this->session->set_userdata('uid', $uid); |
||
| 132 | $this->session->set_userdata('ldap', $user_ldap); |
||
| 133 | $this->session->set_userdata('is_private', $is_private); |
||
| 134 | |||
| 135 | //uses sessions |
||
| 136 | $this->user_model->user_log(); |
||
| 137 | } |
||
| 138 | } |
||
| 139 | } |
||
| 140 | } |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 173 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.