| Conditions | 24 |
| Paths | 6 |
| Total Lines | 163 |
| 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 |
||
| 79 | function wsl_component_watchdog_database() |
||
| 80 | { |
||
| 81 | $assets_base_url = WORDPRESS_SOCIAL_LOGIN_PLUGIN_URL . 'assets/img/16x16/'; |
||
| 82 | |||
| 83 | global $wpdb; |
||
| 84 | |||
| 85 | // If action eq delete WSL user profiles |
||
| 86 | if( isset( $_REQUEST['delete'] ) && isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'] ) ) |
||
| 87 | { |
||
| 88 | if( $_REQUEST['delete'] == 'log' ) |
||
| 89 | { |
||
| 90 | $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}wslwatchdog" ); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | ?> |
||
| 94 | <style> |
||
| 95 | .widefatop td, .widefatop th { border: 1px solid #DDDDDD; } |
||
| 96 | .widefatop th label { font-weight: bold; } |
||
| 97 | </style> |
||
| 98 | |||
| 99 | <div style="padding: 5px 20px; border: 1px solid #ddd; background-color: #fff;"> |
||
| 100 | |||
| 101 | <h3><?php _wsl_e("Authentication log viewer - latest activity", 'wordpress-social-login') ?></h3> |
||
| 102 | |||
| 103 | <p style="float: right;margin-top:-45px"> |
||
| 104 | <?php |
||
| 105 | $delete_url = wp_nonce_url( 'options-general.php?page=wordpress-social-login&wslp=watchdog&delete=log' ); |
||
| 106 | ?> |
||
| 107 | <a class="button button-secondary" style="background-color: #da4f49;border-color: #bd362f;text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);color: #ffffff;" href="<?php echo $delete_url ?>" onClick="return confirm('Are you sure?');"><?php _wsl_e("Delete WSL Log", 'wordpress-social-login'); ?></a> |
||
| 108 | </p> |
||
| 109 | |||
| 110 | <hr /> |
||
| 111 | |||
| 112 | <?php |
||
| 113 | $list_sessions = $wpdb->get_results( "SELECT user_ip, session_id, provider, max(id) as max_id FROM `{$wpdb->prefix}wslwatchdog` GROUP BY session_id, provider ORDER BY max_id DESC LIMIT 25" ); |
||
| 114 | |||
| 115 | if( ! $list_sessions ) |
||
| 116 | { |
||
| 117 | _wsl_e("<p>No log found!</p>", 'wordpress-social-login'); |
||
| 118 | } |
||
| 119 | else |
||
| 120 | { |
||
| 121 | foreach( $list_sessions as $seesion_data ) |
||
| 122 | { |
||
| 123 | $user_ip = $seesion_data->user_ip; |
||
| 124 | $session_id = $seesion_data->session_id; |
||
| 125 | $provider = $seesion_data->provider; |
||
| 126 | |||
| 127 | if( ! $provider ) |
||
| 128 | { |
||
| 129 | continue; |
||
| 130 | } |
||
| 131 | |||
| 132 | ?> |
||
| 133 | <div style="padding: 15px; margin-bottom: 8px; border: 1px solid #ddd; background-color: #fff;box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);"> |
||
| 134 | <img src="<?php echo $assets_base_url . strtolower( $provider ) . '.png' ?>" style="vertical-align:top;width:16px;height:16px;" /> <?php echo sprintf( _wsl__("<b>%s</b> : %s - %s", 'wordpress-social-login'), $provider, $user_ip, $session_id ) ?> |
||
| 135 | </div> |
||
| 136 | |||
| 137 | <table class="wp-list-table widefat widefatop"> |
||
| 138 | <tr> |
||
| 139 | <th>#</th> |
||
| 140 | <th>Action</th> |
||
| 141 | <th>Args</th> |
||
| 142 | <th>Time</th> |
||
| 143 | <th>User</th> |
||
| 144 | <th style="text-align:center">Δ</th> |
||
| 145 | </tr> |
||
| 146 | <?php |
||
| 147 | $list_calls = $wpdb->get_results( "SELECT * FROM `{$wpdb->prefix}wslwatchdog` WHERE session_id = '$session_id' AND provider = '$provider' ORDER BY id ASC LIMIT 500" ); |
||
| 148 | |||
| 149 | $abandon = false; |
||
|
|
|||
| 150 | $newattempt = false; |
||
| 151 | $newsession = true; |
||
| 152 | $functcalls = 0; |
||
| 153 | $exectime = 0; |
||
| 154 | $oexectime = 0; |
||
| 155 | $texectime = 0; |
||
| 156 | |||
| 157 | foreach( $list_calls as $call_data ) |
||
| 158 | { |
||
| 159 | $exectime = (float) $call_data->created_at - ( $oexectime ? $oexectime : (float) $call_data->created_at ); |
||
| 160 | $oexectime = (float) $call_data->created_at; |
||
| 161 | $texectime += $exectime; |
||
| 162 | |||
| 163 | $call_data->action_args = json_decode( $call_data->action_args ); |
||
| 164 | |||
| 165 | $newattempt = false; |
||
| 166 | |||
| 167 | $action_name_uid = uniqid(); |
||
| 168 | |||
| 169 | $action_desc = 'N.A.'; |
||
| 170 | ?> |
||
| 171 | <tr style="<?php if( stristr( $call_data->action_name, 'dbg:' ) ) echo 'background-color:#fffcf5;'; ?> <?php if( 'wsl_render_login_form_user_loggedin' == $call_data->action_name || $call_data->action_name == 'wsl_hook_process_login_before_wp_set_auth_cookie' ) echo 'background-color:#edfff7;'; ?><?php if( 'wsl_process_login_complete_registration_start' == $call_data->action_name ) echo 'background-color:#fefff0;'; ?><?php if( 'wsl_process_login_render_error_page' == $call_data->action_name || $call_data->action_name == 'wsl_process_login_render_notice_page' ) echo 'background-color:#fffafa;'; ?>"> |
||
| 172 | <td nowrap width="10"> |
||
| 173 | <?php echo $call_data->id; ?> |
||
| 174 | </td> |
||
| 175 | <td nowrap width="350"> |
||
| 176 | <span style="color:#<?php |
||
| 177 | if( stristr( $call_data->action_name, 'dbg:' ) ){ |
||
| 178 | echo '333333'; |
||
| 179 | } |
||
| 180 | |||
| 181 | if( 'wsl_hook_process_login_before_wp_safe_redirect' == $call_data->action_name ){ |
||
| 182 | echo 'a6354b'; |
||
| 183 | } |
||
| 184 | |||
| 185 | if( 'wsl_hook_process_login_before_wp_set_auth_cookie' == $call_data->action_name ){ |
||
| 186 | echo '9035a6'; |
||
| 187 | } |
||
| 188 | |||
| 189 | if( 'wsl_process_login_render_error_page' == $call_data->action_name ){ |
||
| 190 | echo 'f50505'; |
||
| 191 | } |
||
| 192 | |||
| 193 | if( 'wsl_process_login_render_notice_page' == $call_data->action_name ){ |
||
| 194 | echo 'fa1797'; |
||
| 195 | } |
||
| 196 | ?>" |
||
| 197 | ><?php echo $call_data->action_name; ?></span> |
||
| 198 | </td> |
||
| 199 | <td> |
||
| 200 | <span style="float:right;"><a style="font-size:25px" href="javascript:void(0);" onClick="action_args_toggle( '<?php echo $action_name_uid; ?>' )">+</a></span> |
||
| 201 | <a href="javascript:alert('<?php echo $call_data->url; ?>');"> |
||
| 202 | <small> |
||
| 203 | <?php |
||
| 204 | echo substr( $call_data->url, 0, 100 ); |
||
| 205 | echo strlen( $call_data->url ) > 100 ? '...' : ''; |
||
| 206 | ?> |
||
| 207 | </small> |
||
| 208 | </a> |
||
| 209 | <pre style="display:none; overflow:scroll; background-color:#fcfcfc; color:#808080;font-size:11px;max-width:750px;" class="action_args_<?php echo $action_name_uid; ?>"><?php echo htmlentities( print_r( $call_data->action_args, true ) ); ?></pre> |
||
| 210 | </td> |
||
| 211 | <td nowrap width="115"> |
||
| 212 | <?php echo date( "Y-m-d h:i:s", $call_data->created_at ); ?> |
||
| 213 | </td> |
||
| 214 | <td nowrap width="40"> |
||
| 215 | <?php if( $call_data->user_id ) echo '<a href="options-general.php?page=wordpress-social-login&wslp=users&uid=' . $call_data->user_id . '">#' . $call_data->user_id . '</a>'; ?> |
||
| 216 | </td> |
||
| 217 | <td nowrap width="10" style="<?php if( $exectime > 0.5 ) echo 'color: #f44 !important;'; ?>"> |
||
| 218 | <?php echo number_format( $exectime, 3, '.', '' ); ?> |
||
| 219 | </td> |
||
| 220 | </tr> |
||
| 221 | <?php |
||
| 222 | } |
||
| 223 | ?> |
||
| 224 | </table> |
||
| 225 | <?php |
||
| 226 | echo number_format( $texectime, 3, '.', '' ); |
||
| 227 | echo '<br />'; |
||
| 228 | } |
||
| 229 | } |
||
| 230 | ?> |
||
| 231 | <script> |
||
| 232 | function action_args_toggle( action ) |
||
| 233 | { |
||
| 234 | jQuery('.action_args_' + action ).toggle(); |
||
| 235 | |||
| 236 | return false; |
||
| 237 | } |
||
| 238 | </script> |
||
| 239 | </div> |
||
| 240 | <?php |
||
| 241 | } |
||
| 242 | |||
| 244 |
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.