| Conditions | 4 |
| Paths | 4 |
| Total Lines | 95 |
| Code Lines | 52 |
| Lines | 6 |
| Ratio | 6.32 % |
| 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 |
||
| 158 | public function approve() { |
||
| 159 | |||
| 160 | if (in_array('CN=DG06,OU=Distribution Groups,OU=Email Groups,OU=Accounts,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) { |
||
| 161 | |||
| 162 | if (isset($_GET['id'])) { |
||
| 163 | |||
| 164 | $id = $_GET['id']; |
||
| 165 | //$this->temporary_account_model->approve($id); |
||
| 166 | |||
| 167 | $function = 'temp_account_APPROVED_' . $id; |
||
| 168 | $this->user_model->function_log($function); |
||
| 169 | |||
| 170 | $data = array(); |
||
| 171 | $data['AD'] = $this->temporary_account_model->get_account($id); |
||
| 172 | |||
| 173 | //AD account start |
||
| 174 | //AD Server |
||
| 175 | $AD_server = $this->config->item('ldapserver'); |
||
| 176 | $AD_Auth_User = $this->config->item('ldapshortdomain').$this->config->item('ldapadminun'); //Administrative user |
||
| 177 | $AD_Auth_PWD = $this->config->item('ldapadminpass'); //The password |
||
| 178 | //Create Active Directory timestamp |
||
| 179 | date_default_timezone_set($this->config->item('timezone')); |
||
| 180 | |||
| 181 | //Format dd-mm-yyyy |
||
| 182 | //Expiry is beginning of day (thats why +1 day |
||
| 183 | $dateFromForm = date('d-m-Y', strtotime($data['AD'][0]['expiry']. ' +1 day')); |
||
| 184 | |||
| 185 | //Format hh:mm:ss |
||
| 186 | $timeFromForm = "00:00:00"; |
||
| 187 | |||
| 188 | $dateWithTime = $dateFromForm . " " . $timeFromForm; |
||
| 189 | |||
| 190 | View Code Duplication | function convertDateToUnix($input) { |
|
| 191 | $format = 'd-m-Y H:i:s'; |
||
| 192 | $date = DateTime::createFromFormat($format, $input); |
||
| 193 | $UNIXTimestamp = $date->getTimestamp(); |
||
| 194 | return $UNIXTimestamp; |
||
| 195 | } |
||
| 196 | |||
| 197 | function convertUnixtoWin($input) { |
||
| 198 | return ($input + 11644473600) * 10000000; |
||
| 199 | } |
||
| 200 | |||
| 201 | //$UNIX = convertDateToUnix($dateWithTime); |
||
| 202 | //$WIN = convertUnixtoWin($UNIX); |
||
| 203 | |||
| 204 | //Create Unicode password |
||
| 205 | $passwordWithQuotes = '"' . $data['AD'][0]['password'] . '"'; |
||
| 206 | $ldaprecord = array(); |
||
| 207 | $ldaprecord["unicodepwd"] = iconv('UTF-8', 'UTF-16LE', $passwordWithQuotes); |
||
| 208 | |||
| 209 | //Build Active Directory record |
||
| 210 | $ldaprecord["cn"] = $data['AD'][0]['username']; |
||
| 211 | $ldaprecord["givenName"] = $data['AD'][0]['first_name']; |
||
| 212 | $ldaprecord["sn"] = $data['AD'][0]['last_name']; |
||
| 213 | $ldaprecord["mail"] = $data['AD'][0]['email']; |
||
| 214 | $ldaprecord["sAMAccountName"] = $data['AD'][0]['username']; |
||
| 215 | $ldaprecord["displayName"] = $data['AD'][0]['first_name'] . " " . $data['AD'][0]['last_name']; |
||
| 216 | $ldaprecord["l"] = "Canterbury"; |
||
| 217 | $ldaprecord["description"] = "Temp account created by dashboard for " . $ldaprecord["displayName"]; |
||
| 218 | //$ldaprecord["accountExpires"] = $WIN; |
||
| 219 | $ldaprecord["UserAccountControl"] = "512"; //512 - Enabled Account |
||
| 220 | $ldaprecord['userPrincipalName'] = $data['AD'][0]['username'] . '@cant-col.ac.uk'; |
||
| 221 | $ldaprecord['objectclass'][0] = "top"; |
||
| 222 | $ldaprecord['objectclass'][1] = "person"; |
||
| 223 | $ldaprecord['objectclass'][2] = "organizationalPerson"; |
||
| 224 | $ldaprecord['objectclass'][3] = "user"; |
||
| 225 | $dn = 'CN=' . $ldaprecord["cn"] . ',OU=Temp Accounts,OU=Students,OU=Accounts,DC=cant-col,DC=ac,DC=uk'; |
||
| 226 | |||
| 227 | // Connect to Active Directory |
||
| 228 | $ds = ldap_connect('ldaps://' . $AD_server); |
||
| 229 | |||
| 230 | if ($ds) { |
||
| 231 | ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); |
||
| 232 | ldap_bind($ds, $AD_Auth_User, $AD_Auth_PWD); //Bind |
||
| 233 | ldap_add($ds, $dn, $ldaprecord); //Create account |
||
| 234 | ldap_close($ds); //Close connection |
||
| 235 | $this->temporary_account_model->created_account($id); |
||
| 236 | } else { |
||
| 237 | //redirect('computing-support/temporary-account/error?id='.$id); |
||
| 238 | } |
||
| 239 | //AD account end. |
||
| 240 | |||
| 241 | //redirect($_SERVER['HTTP_REFERER']); |
||
| 242 | $this->load->view('templates/header'); |
||
| 243 | $this->load->view('computing-support/temporary-account/view'); |
||
| 244 | $this->load->view('templates/footer'); |
||
| 245 | |||
| 246 | } |
||
| 247 | |||
| 248 | //redirect($_SERVER['HTTP_REFERER']); |
||
| 249 | } else { |
||
| 250 | //redirect($_SERVER['HTTP_REFERER']); |
||
| 251 | } |
||
| 252 | } |
||
| 253 | |||
| 266 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.