Skip to content

Commit

Permalink
Coding Standards: Use pre-increment/decrement for stand-alone stateme…
Browse files Browse the repository at this point in the history
…nts.

Note: This is enforced by WPCS 3.0.0:

1. There should be no space between an increment/decrement operator and the variable it applies to.
2. Pre-increment/decrement should be favoured over post-increment/decrement for stand-alone statements. “Pre” will in/decrement and then return, “post” will return and then in/decrement. Using the “pre” version is slightly more performant and can prevent future bugs when code gets moved around.

References:
* [https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#increment-decrement-operators WordPress PHP Coding Standards: Increment/decrement operators]
* [WordPress/WordPress-Coding-Standards#2130 WPCS: PR WordPress#2130 Core: add sniffs to check formatting of increment/decrement operators]

Props jrf.
See #59161, #58831.

git-svn-id: https://develop.svn.wordpress.org/trunk@56549 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov authored and SergeyBiryukov committed Sep 9, 2023
1 parent 1118e37 commit 54e1b4b
Show file tree
Hide file tree
Showing 95 changed files with 212 additions and 212 deletions.
14 changes: 7 additions & 7 deletions src/wp-admin/edit-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,31 @@
switch ( $doaction ) {
case 'approve':
wp_set_comment_status( $comment_id, 'approve' );
$approved++;
++$approved;
break;
case 'unapprove':
wp_set_comment_status( $comment_id, 'hold' );
$unapproved++;
++$unapproved;
break;
case 'spam':
wp_spam_comment( $comment_id );
$spammed++;
++$spammed;
break;
case 'unspam':
wp_unspam_comment( $comment_id );
$unspammed++;
++$unspammed;
break;
case 'trash':
wp_trash_comment( $comment_id );
$trashed++;
++$trashed;
break;
case 'untrash':
wp_untrash_comment( $comment_id );
$untrashed++;
++$untrashed;
break;
case 'delete':
wp_delete_comment( $comment_id );
$deleted++;
++$deleted;
break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/wp-admin/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@
}

if ( wp_check_post_lock( $post_id ) ) {
$locked++;
++$locked;
continue;
}

if ( ! wp_trash_post( $post_id ) ) {
wp_die( __( 'Error in moving the item to Trash.' ) );
}

$trashed++;
++$trashed;
}

$sendback = add_query_arg(
Expand Down Expand Up @@ -160,7 +160,7 @@
wp_die( __( 'Error in restoring the item from Trash.' ) );
}

$untrashed++;
++$untrashed;
}
$sendback = add_query_arg( 'untrashed', $untrashed, $sendback );

Expand All @@ -185,7 +185,7 @@
wp_die( __( 'Error in deleting the item.' ) );
}
}
$deleted++;
++$deleted;
}
$sendback = add_query_arg( 'deleted', $deleted, $sendback );
break;
Expand Down
6 changes: 3 additions & 3 deletions src/wp-admin/includes/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,7 @@ function wp_ajax_inline_save() {
while ( $parent > 0 ) {
$parent_post = get_post( $parent );
$parent = $parent_post->post_parent;
$level++;
++$level;
}
}

Expand Down Expand Up @@ -2211,7 +2211,7 @@ function wp_ajax_inline_save_tax() {
while ( $parent > 0 ) {
$parent_tag = get_term( $parent, $taxonomy );
$parent = $parent_tag->parent;
$level++;
++$level;
}

$wp_list_table->single_row( $tag, $level );
Expand Down Expand Up @@ -2821,7 +2821,7 @@ function wp_ajax_set_attachment_thumbnail() {
}

if ( set_post_thumbnail( $post_id, $thumbnail_id ) ) {
$success++;
++$success;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-language-pack-upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function bulk_upgrade( $language_updates = array(), $args = array() ) {
$destination .= '/themes';
}

$this->update_current++;
++$this->update_current;

$options = array(
'package' => $language_update->package,
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-plugin-upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public function bulk_upgrade( $plugins, $args = array() ) {
$this->update_count = count( $plugins );
$this->update_current = 0;
foreach ( $plugins as $plugin ) {
$this->update_current++;
++$this->update_current;
$this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true );

if ( ! isset( $current->response[ $plugin ] ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-theme-upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public function bulk_upgrade( $themes, $args = array() ) {
$this->update_count = count( $themes );
$this->update_current = 0;
foreach ( $themes as $theme ) {
$this->update_current++;
++$this->update_current;

$this->skin->theme_info = $this->theme_info( $theme );

Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/class-wp-automatic-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ protected function send_debug_email() {
} else {
/* translators: %s: WordPress version. */
$body[] = sprintf( __( 'FAILED: WordPress failed to update to %s' ), $result->name );
$failures++;
++$failures;
}

$body[] = '';
Expand Down Expand Up @@ -1432,7 +1432,7 @@ protected function send_debug_email() {
if ( ! $item->result || is_wp_error( $item->result ) ) {
/* translators: %s: Name of plugin / theme / translation. */
$body[] = ' * ' . sprintf( __( 'FAILED: %s' ), $item->name );
$failures++;
++$failures;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-wp-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ public function print_column_headers( $with_id = true ) {
'</span>' .
'</label>' .
'<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
$cb_counter++;
++$cb_counter;
}

foreach ( $columns as $column_key => $column_display_name ) {
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-wp-plugins-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ public function single_row( $item ) {
$suffix = 2;
while ( in_array( $plugin_id_attr, $plugin_id_attrs, true ) ) {
$plugin_id_attr = "$plugin_slug-$suffix";
$suffix++;
++$suffix;
}

$plugin_id_attrs[] = $plugin_id_attr;
Expand Down
12 changes: 6 additions & 6 deletions src/wp-admin/includes/class-wp-posts-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 2
$to_display[ $page->ID ] = $level;
}

$count++;
++$count;

if ( isset( $children_pages ) ) {
$this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
Expand All @@ -917,7 +917,7 @@ private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 2
$to_display[ $op->ID ] = 0;
}

$count++;
++$count;
}
}
}
Expand Down Expand Up @@ -992,15 +992,15 @@ private function _page_rows( &$children_pages, &$count, $parent_page, $level, $p

while ( $my_parent = array_pop( $my_parents ) ) {
$to_display[ $my_parent->ID ] = $level - $num_parents;
$num_parents--;
--$num_parents;
}
}

if ( $count >= $start ) {
$to_display[ $page->ID ] = $level;
}

$count++;
++$count;

$this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
}
Expand Down Expand Up @@ -1097,7 +1097,7 @@ public function column_title( $post ) {
break;
}

$this->current_level++;
++$this->current_level;
$find_main_page = (int) $parent->post_parent;

if ( ! isset( $parent_name ) ) {
Expand Down Expand Up @@ -2085,7 +2085,7 @@ public function inline_edit() {
</td></tr>

<?php
$bulk++;
++$bulk;
endwhile;
?>
</tbody></table>
Expand Down
10 changes: 5 additions & 5 deletions src/wp-admin/includes/class-wp-privacy-requests-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ public function process_bulk_action() {
$resend = _wp_privacy_resend_request( $request_id );

if ( $resend && ! is_wp_error( $resend ) ) {
$count++;
++$count;
} else {
$failures++;
++$failures;
}
}

Expand Down Expand Up @@ -286,7 +286,7 @@ public function process_bulk_action() {
$result = _wp_privacy_completed_request( $request_id );

if ( $result && ! is_wp_error( $result ) ) {
$count++;
++$count;
}
}

Expand All @@ -309,9 +309,9 @@ public function process_bulk_action() {
case 'delete':
foreach ( $request_ids as $request_id ) {
if ( wp_delete_post( $request_id, true ) ) {
$count++;
++$count;
} else {
$failures++;
++$failures;
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/wp-admin/includes/class-wp-site-health.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,14 @@ public function get_test_plugin_version() {

// Loop over the available plugins and check their versions and active state.
foreach ( $plugins as $plugin_path => $plugin ) {
$plugins_total++;
++$plugins_total;

if ( is_plugin_active( $plugin_path ) ) {
$plugins_active++;
++$plugins_active;
}

if ( array_key_exists( $plugin_path, $plugin_updates ) ) {
$plugins_need_update++;
++$plugins_need_update;
}
}

Expand Down Expand Up @@ -543,21 +543,21 @@ public function get_test_theme_version() {
}

foreach ( $all_themes as $theme_slug => $theme ) {
$themes_total++;
++$themes_total;

if ( array_key_exists( $theme_slug, $theme_updates ) ) {
$themes_need_updates++;
++$themes_need_updates;
}
}

// If this is a child theme, increase the allowed theme count by one, to account for the parent.
if ( is_child_theme() ) {
$allowed_theme_count++;
++$allowed_theme_count;
}

// If there's a default theme installed and not in use, we count that as allowed as well.
if ( $has_default_theme && ! $using_default_theme ) {
$allowed_theme_count++;
++$allowed_theme_count;
}

if ( $themes_total > $allowed_theme_count ) {
Expand Down Expand Up @@ -3293,11 +3293,11 @@ public function wp_cron_scheduled_check() {

foreach ( $results as $result ) {
if ( 'critical' === $result['status'] ) {
$site_status['critical']++;
++$site_status['critical'];
} elseif ( 'recommended' === $result['status'] ) {
$site_status['recommended']++;
++$site_status['recommended'];
} else {
$site_status['good']++;
++$site_status['good'];
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-wp-terms-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ private function _rows( $taxonomy, $terms, &$children, $start, $per_page, &$coun
while ( $my_parent = array_pop( $my_parents ) ) {
echo "\t";
$this->single_row( $my_parent, $level - $num_parents );
$num_parents--;
--$num_parents;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ function verify_file_signature( $filename, $signatures, $filename_for_errors = f

// Ensure only valid-length signatures are considered.
if ( SODIUM_CRYPTO_SIGN_BYTES !== strlen( $signature_raw ) ) {
$skipped_signature++;
++$skipped_signature;
continue;
}

Expand All @@ -1502,7 +1502,7 @@ function verify_file_signature( $filename, $signatures, $filename_for_errors = f

// Only pass valid public keys through.
if ( SODIUM_CRYPTO_SIGN_PUBLICKEYBYTES !== strlen( $key_raw ) ) {
$skipped_key++;
++$skipped_key;
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/image-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ function wp_save_image( $post_id ) {
$new_path = "{$dirname}/$new_filename";

if ( file_exists( $new_path ) ) {
$suffix++;
++$suffix;
} else {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ function wp_iframe( $content_func, ...$args ) {
*/
function media_buttons( $editor_id = 'content' ) {
static $instance = 0;
$instance++;
++$instance;

$post = get_post();

Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function add_menu_classes( $menu ) {
$i = 0;

foreach ( $menu as $order => $top ) {
$i++;
++$i;

if ( 0 === $order ) { // Dashboard is always shown/single.
$menu[0][4] = add_cssclass( 'menu-top-first', $top[4] );
Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ function wp_print_theme_file_tree( $tree, $level = 2, $size = 1, $index = 1 ) {
$size = count( $tree );

foreach ( $tree as $label => $theme_file ) :
$index++;
++$index;

if ( ! is_array( $theme_file ) ) {
wp_print_theme_file_tree( $theme_file, $level, $index, $size );
Expand Down Expand Up @@ -505,7 +505,7 @@ function wp_print_plugin_file_tree( $tree, $label = '', $level = 2, $size = 1, $
$size = count( $tree );

foreach ( $tree as $label => $plugin_file ) :
$index++;
++$index;

if ( ! is_array( $plugin_file ) ) {
wp_print_plugin_file_tree( $plugin_file, $label, $level, $index, $size );
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/ms.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ function avoid_blog_page_permalink_collision( $data, $postarr ) {

while ( $c < 10 && get_id_from_blogname( $post_name ) ) {
$post_name .= mt_rand( 1, 10 );
$c++;
++$c;
}

if ( $post_name !== $data['post_name'] ) {
Expand Down
Loading

0 comments on commit 54e1b4b

Please sign in to comment.