| Conditions | 10 |
| Paths | 11 |
| Total Lines | 75 |
| Code Lines | 60 |
| Lines | 9 |
| Ratio | 12 % |
| 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 |
||
| 14 | public function signIn() |
||
| 15 | { |
||
| 16 | $settings = require('config/settings.php'); |
||
| 17 | if ($settings['steamlogin']) { |
||
| 18 | require_once 'openid.php'; |
||
| 19 | $openid = new LightOpenID($settings['url']); |
||
| 20 | if (!$openid->mode) { |
||
| 21 | $openid->identity = 'http://steamcommunity.com/openid'; |
||
| 22 | header('Location: ' . $openid->authUrl()); |
||
| 23 | } elseif ($openid->mode == 'cancel') { |
||
| 24 | print ('User has canceled authentication!'); |
||
| 25 | } else { |
||
| 26 | if ($openid->validate()) { |
||
| 27 | preg_match("/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/", $openid->identity, $matches); |
||
| 28 | $_SESSION['playerid'] = $matches[1]; |
||
| 29 | |||
| 30 | $db_connection = masterConnect(); |
||
| 31 | |||
| 32 | $sql = "SELECT user_name, user_email, user_level, user_profile, permissions, user_password_hash, user_id |
||
| 33 | FROM users WHERE playerid = '" . $_SESSION['playerid'] . "';"; |
||
| 34 | $result_of_login_check = $db_connection->query($sql); |
||
| 35 | |||
| 36 | if ($result_of_login_check->num_rows == 1) { |
||
| 37 | $result_row = $result_of_login_check->fetch_object(); |
||
| 38 | if ($result_row->user_level <> 0) { |
||
| 39 | $_SESSION['user_name'] = $result_row->user_name; |
||
| 40 | $_SESSION['user_level'] = $result_row->user_level; |
||
| 41 | $_SESSION['user_profile'] = $result_row->user_profile; |
||
| 42 | $_SESSION['user_email'] = $result_row->user_email; |
||
| 43 | $_SESSION['user_id'] = $result_row->user_id; |
||
| 44 | $_SESSION['permissions'] = json_decode($result_row->permissions, true); |
||
| 45 | View Code Duplication | if (isset($result_row->items)) { |
|
| 46 | $_SESSION['items'] = $result_row->items; |
||
| 47 | } else { |
||
| 48 | $_SESSION['items'] = $settings['items']; |
||
| 49 | } |
||
| 50 | if (isset($_POST['lang'])) { |
||
| 51 | $_SESSION['lang'] = $_POST['lang']; |
||
| 52 | } |
||
| 53 | $_SESSION['user_login_status'] = 1; |
||
| 54 | $_SESSION['steamsignon'] = false; //used to determine if its a single sign on with no account |
||
| 55 | multiDB(); |
||
| 56 | |||
| 57 | logAction($_SESSION['user_name'], 'Successful Steam Login (' . $_SERVER['REMOTE_ADDR'] . ')', 2); |
||
| 58 | View Code Duplication | } else { |
|
| 59 | $this->errors[] = "User is banned."; |
||
| 60 | logAction($_POST['user_name'], 'Steam Login Failed - Banned User (' . $_SERVER['REMOTE_ADDR'] . ')', 3); |
||
| 61 | } |
||
| 62 | } else { |
||
| 63 | if ($settings['annonlogin']) { |
||
| 64 | $permissions = require('config/permissions.php'); |
||
| 65 | $steam = $this->GetPlayerSummaries($_SESSION['playerid']); |
||
| 66 | $_SESSION['user_name'] = $steam->personaname; |
||
| 67 | $_SESSION['user_level'] = 1; |
||
| 68 | $_SESSION['user_profile'] = $steam->avatarmedium; |
||
| 69 | $_SESSION['permissions'] = $permissions[1]; |
||
| 70 | $_SESSION['items'] = $settings['items']; |
||
| 71 | $_SESSION['user_login_status'] = 1; |
||
| 72 | $_SESSION['profile_link'] = $steam->profileurl; |
||
| 73 | $_SESSION['steamsignon'] = true; //used to determine if its a single sign on with no account |
||
| 74 | multiDB(); |
||
| 75 | |||
| 76 | logAction($_SESSION['user_name'], 'Successful Steam Login (' . $_SERVER['REMOTE_ADDR'] . ')', 2); |
||
| 77 | } else { |
||
| 78 | errorMessage(7); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | header('Location: ' . $settings['url']); |
||
| 82 | exit; |
||
| 83 | } else { |
||
| 84 | print ('Error'); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 98 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.