| Conditions | 2 |
| Paths | 2 |
| Total Lines | 211 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 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 |
||
| 78 | function post_page_metabox_assets() { |
||
| 79 | global $post; |
||
| 80 | $user_id = empty( $post->post_author ) ? $GLOBALS['user_ID'] : $post->post_author; |
||
|
|
|||
| 81 | |||
| 82 | $default_prefix = $this->publicize->default_prefix; |
||
| 83 | $default_prefix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_prefix ) ); |
||
| 84 | |||
| 85 | $default_message = $this->publicize->default_message; |
||
| 86 | $default_message = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_message ) ); |
||
| 87 | |||
| 88 | $default_suffix = $this->publicize->default_suffix; |
||
| 89 | $default_suffix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_suffix ) ); ?> |
||
| 90 | |||
| 91 | <script type="text/javascript"> |
||
| 92 | jQuery( function($) { |
||
| 93 | var wpasTitleCounter = $( '#wpas-title-counter' ), |
||
| 94 | wpasTwitterCheckbox = $( '.wpas-submit-twitter' ).size(), |
||
| 95 | wpasTitle = $('#wpas-title').keyup( function() { |
||
| 96 | var length = wpasTitle.val().length; |
||
| 97 | wpasTitleCounter.text( length ); |
||
| 98 | if ( wpasTwitterCheckbox && length > 140 ) { |
||
| 99 | wpasTitleCounter.addClass( 'wpas-twitter-length-limit' ); |
||
| 100 | } else { |
||
| 101 | wpasTitleCounter.removeClass( 'wpas-twitter-length-limit' ); |
||
| 102 | } |
||
| 103 | } ), |
||
| 104 | authClick = false; |
||
| 105 | |||
| 106 | $('#publicize-disconnected-form-show').click( function() { |
||
| 107 | $('#publicize-form').slideDown( 'fast' ); |
||
| 108 | $(this).hide(); |
||
| 109 | } ); |
||
| 110 | |||
| 111 | $('#publicize-disconnected-form-hide').click( function() { |
||
| 112 | $('#publicize-form').slideUp( 'fast' ); |
||
| 113 | $('#publicize-disconnected-form-show').show(); |
||
| 114 | } ); |
||
| 115 | |||
| 116 | $('#publicize-form-edit').click( function() { |
||
| 117 | $('#publicize-form').slideDown( 'fast', function() { |
||
| 118 | wpasTitle.focus(); |
||
| 119 | if ( !wpasTitle.text() ) { |
||
| 120 | var url = $('#shortlink').size() ? $('#shortlink').val() : ''; |
||
| 121 | |||
| 122 | var defaultMessage = $.trim( '<?php printf( $default_prefix, 'url' ); printf( $default_message, '$("#title").val()', 'url' ); printf( $default_suffix, 'url' ); ?>' ); |
||
| 123 | |||
| 124 | wpasTitle.append( defaultMessage.replace( /<[^>]+>/g,'') ); |
||
| 125 | |||
| 126 | var selBeg = defaultMessage.indexOf( $("#title").val() ); |
||
| 127 | if ( selBeg < 0 ) { |
||
| 128 | selBeg = 0; |
||
| 129 | selEnd = 0; |
||
| 130 | } else { |
||
| 131 | selEnd = selBeg + $("#title").val().length; |
||
| 132 | } |
||
| 133 | |||
| 134 | var domObj = wpasTitle.get(0); |
||
| 135 | if ( domObj.setSelectionRange ) { |
||
| 136 | domObj.setSelectionRange( selBeg, selEnd ); |
||
| 137 | } else if ( domObj.createTextRange ) { |
||
| 138 | var r = domObj.createTextRange(); |
||
| 139 | r.moveStart( 'character', selBeg ); |
||
| 140 | r.moveEnd( 'character', selEnd ); |
||
| 141 | r.select(); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | wpasTitle.keyup(); |
||
| 145 | } ); |
||
| 146 | $('#publicize-defaults').hide(); |
||
| 147 | $(this).hide(); |
||
| 148 | return false; |
||
| 149 | } ); |
||
| 150 | |||
| 151 | $('#publicize-form-hide').click( function() { |
||
| 152 | var newList = $.map( $('#publicize-form').slideUp( 'fast' ).find( ':checked' ), function( el ) { |
||
| 153 | return $.trim( $(el).parent( 'label' ).text() ); |
||
| 154 | } ); |
||
| 155 | $('#publicize-defaults').html( '<strong>' + newList.join( '</strong>, <strong>' ) + '</strong>' ).show(); |
||
| 156 | $('#publicize-form-edit').show(); |
||
| 157 | return false; |
||
| 158 | } ); |
||
| 159 | |||
| 160 | $('.authorize-link').click( function() { |
||
| 161 | if ( authClick ) { |
||
| 162 | return false; |
||
| 163 | } |
||
| 164 | authClick = true; |
||
| 165 | $(this).after( '<img src="images/loading.gif" class="alignleft" style="margin: 0 .5em" />' ); |
||
| 166 | $.ajaxSetup( { async: false } ); |
||
| 167 | |||
| 168 | if ( window.wp && window.wp.autosave ) { |
||
| 169 | window.wp.autosave.server.triggerSave(); |
||
| 170 | } else { |
||
| 171 | autosave(); |
||
| 172 | } |
||
| 173 | |||
| 174 | return true; |
||
| 175 | } ); |
||
| 176 | |||
| 177 | $( '.pub-service' ).click( function() { |
||
| 178 | var service = $(this).data( 'service' ), |
||
| 179 | fakebox = '<input id="wpas-submit-' + service + '" type="hidden" value="1" name="wpas[submit][' + service + ']" />'; |
||
| 180 | $( '#add-publicize-check' ).append( fakebox ); |
||
| 181 | } ); |
||
| 182 | |||
| 183 | publicizeConnTestStart = function() { |
||
| 184 | $( '#pub-connection-tests' ) |
||
| 185 | .removeClass( 'below-h2' ) |
||
| 186 | .removeClass( 'error' ) |
||
| 187 | .removeClass( 'publicize-token-refresh-message' ) |
||
| 188 | .addClass( 'test-in-progress' ) |
||
| 189 | .html( '' ); |
||
| 190 | $.post( ajaxurl, { action: 'test_publicize_conns' }, publicizeConnTestComplete ); |
||
| 191 | } |
||
| 192 | |||
| 193 | publicizeConnRefreshClick = function( event ) { |
||
| 194 | event.preventDefault(); |
||
| 195 | var popupURL = event.currentTarget.href; |
||
| 196 | var popupTitle = event.currentTarget.title; |
||
| 197 | // open a popup window |
||
| 198 | // when it is closed, kick off the tests again |
||
| 199 | var popupWin = window.open( popupURL, popupTitle, '' ); |
||
| 200 | var popupWinTimer= window.setInterval( function() { |
||
| 201 | if ( popupWin.closed !== false ) { |
||
| 202 | window.clearInterval( popupWinTimer ); |
||
| 203 | publicizeConnTestStart(); |
||
| 204 | } |
||
| 205 | }, 500 ); |
||
| 206 | } |
||
| 207 | |||
| 208 | publicizeConnTestComplete = function( response ) { |
||
| 209 | var testsSelector = $( '#pub-connection-tests' ); |
||
| 210 | testsSelector |
||
| 211 | .removeClass( 'test-in-progress' ) |
||
| 212 | .removeClass( 'below-h2' ) |
||
| 213 | .removeClass( 'error' ) |
||
| 214 | .removeClass( 'publicize-token-refresh-message' ) |
||
| 215 | .html( '' ); |
||
| 216 | |||
| 217 | // If any of the tests failed, show some stuff |
||
| 218 | var somethingShownAlready = false; |
||
| 219 | $.each( response.data, function( index, testResult ) { |
||
| 220 | // find the li for this connection |
||
| 221 | if ( ! testResult.connectionTestPassed ) { |
||
| 222 | if ( ! somethingShownAlready ) { |
||
| 223 | testsSelector |
||
| 224 | .addClass( 'below-h2' ) |
||
| 225 | .addClass( 'error' ) |
||
| 226 | .addClass( 'publicize-token-refresh-message' ) |
||
| 227 | .append( "<p><?php echo esc_html( __( 'Before you hit Publish, please refresh the following connection(s) to make sure we can Publicize your post:', 'jetpack' ) ); ?></p>" ); |
||
| 228 | somethingShownAlready = true; |
||
| 229 | } |
||
| 230 | |||
| 231 | if ( testResult.userCanRefresh ) { |
||
| 232 | testsSelector.append( '<p/>' ); |
||
| 233 | $( '<a/>', { |
||
| 234 | 'class' : 'pub-refresh-button button', |
||
| 235 | 'title' : testResult.refreshText, |
||
| 236 | 'href' : testResult.refreshURL, |
||
| 237 | 'text' : testResult.refreshText, |
||
| 238 | 'target' : '_refresh_' + testResult.serviceName |
||
| 239 | } ) |
||
| 240 | .appendTo( testsSelector.children().last() ) |
||
| 241 | .click( publicizeConnRefreshClick ); |
||
| 242 | } |
||
| 243 | } |
||
| 244 | } ); |
||
| 245 | } |
||
| 246 | |||
| 247 | $( document ).ready( function() { |
||
| 248 | // If we have the #pub-connection-tests div present, kick off the connection test |
||
| 249 | if ( $( '#pub-connection-tests' ).length ) { |
||
| 250 | publicizeConnTestStart(); |
||
| 251 | } |
||
| 252 | } ); |
||
| 253 | |||
| 254 | } ); |
||
| 255 | </script> |
||
| 256 | |||
| 257 | <style type="text/css"> |
||
| 258 | #publicize { |
||
| 259 | line-height: 1.5; |
||
| 260 | } |
||
| 261 | #publicize ul { |
||
| 262 | margin: 4px 0 4px 6px; |
||
| 263 | } |
||
| 264 | #publicize li { |
||
| 265 | margin: 0; |
||
| 266 | } |
||
| 267 | #publicize textarea { |
||
| 268 | margin: 4px 0 0; |
||
| 269 | width: 100% |
||
| 270 | } |
||
| 271 | #publicize ul.not-connected { |
||
| 272 | list-style: square; |
||
| 273 | padding-left: 1em; |
||
| 274 | } |
||
| 275 | .post-new-php .authorize-link, .post-php .authorize-link { |
||
| 276 | line-height: 1.5em; |
||
| 277 | } |
||
| 278 | .post-new-php .authorize-message, .post-php .authorize-message { |
||
| 279 | margin-bottom: 0; |
||
| 280 | } |
||
| 281 | #poststuff #publicize .updated p { |
||
| 282 | margin: .5em 0; |
||
| 283 | } |
||
| 284 | .wpas-twitter-length-limit { |
||
| 285 | color: red; |
||
| 286 | } |
||
| 287 | </style><?php |
||
| 288 | } |
||
| 289 | |||
| 544 |
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.