Conditions | 7 |
Paths | 7 |
Total Lines | 54 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
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'); |
||
5 | function __construct() { |
||
|
|||
6 | parent::__construct(); |
||
7 | $this->load->model('user_model'); |
||
8 | |||
9 | if (isset($_COOKIE['CI-CONCRETE5']) === TRUE) { |
||
10 | |||
11 | $cookie = $_COOKIE['CI-CONCRETE5']; |
||
12 | $key = $this->config->item('concrete5authkey'); |
||
13 | $username = $this->user_model->decrypt($key, $cookie); |
||
14 | |||
15 | if ($this->user_model->user_exist($username) === FALSE) { |
||
16 | |||
17 | //expire fake cookie |
||
18 | setcookie('CI-CONCRETE5', 'expired', time() - (1), "/"); |
||
19 | } else { |
||
20 | |||
21 | $user_ldap = $this->user_model->user_ldap($username); |
||
22 | |||
23 | if ($user_ldap['useraccountcontrol'] == '66050') { |
||
24 | // disabled, password never expire |
||
25 | redirect('http://'.$_SERVER['HTTP_HOST'].'/authentication/user-disabled'); |
||
26 | } elseif ($user_ldap['useraccountcontrol'] == '514') { |
||
27 | // disabled |
||
28 | redirect('/authentication/user-disabled'); |
||
29 | } else { |
||
30 | |||
31 | if (!in_array('CN=Staff,OU=Groups,DC=cant-col,DC=ac,DC=uk', $user_ldap['groups'])) { |
||
32 | |||
33 | redirect('http://'.$_SERVER['HTTP_HOST'].'/authentication/user-disabled'); |
||
34 | } else { |
||
35 | |||
36 | $ip = $_SERVER['REMOTE_ADDR']; |
||
37 | $is_private = $this->user_model->ip_is_private($ip); |
||
38 | $uid = $this->user_model->get_uid_from_username($username); |
||
39 | $this->user_model->set_user($uid, $username, $ip); |
||
40 | |||
41 | $this->session->set_userdata('username', $username); |
||
42 | $this->session->set_userdata('uid', $uid); |
||
43 | $this->session->set_userdata('ldap', $user_ldap); |
||
44 | $this->session->set_userdata('is_private', $is_private); |
||
45 | |||
46 | //uses sessions |
||
47 | $this->user_model->user_log(); |
||
48 | |||
49 | if ($is_private === TRUE) { |
||
50 | |||
51 | // reset as internal |
||
52 | $this->user_model->external_login_reset($uid); |
||
53 | } |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | } |
||
58 | } |
||
59 | |||
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.