Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-importer.php

    r41628 r42343  
    66    /**
    77     * Class Constructor
    8      *
    98     */
    109    public function __construct() {}
     
    2423        $hashtable = array();
    2524
    26         $limit = 100;
     25        $limit  = 100;
    2726        $offset = 0;
    2827
     
    3029        do {
    3130            $meta_key = $importer_name . '_' . $bid . '_permalink';
    32             $sql = $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s LIMIT %d,%d", $meta_key, $offset, $limit );
    33             $results = $wpdb->get_results( $sql );
     31            $sql      = $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s LIMIT %d,%d", $meta_key, $offset, $limit );
     32            $results  = $wpdb->get_results( $sql );
    3433
    3534            // Increment offset
    3635            $offset = ( $limit + $offset );
    3736
    38             if ( !empty( $results ) ) {
     37            if ( ! empty( $results ) ) {
    3938                foreach ( $results as $r ) {
    4039                    // Set permalinks into array
    41                     $hashtable[$r->meta_value] = intval( $r->post_id );
     40                    $hashtable[ $r->meta_value ] = intval( $r->post_id );
    4241                }
    4342            }
     
    6665        // Get count of permalinks
    6766        $meta_key = $importer_name . '_' . $bid . '_permalink';
    68         $sql = $wpdb->prepare( "SELECT COUNT( post_id ) AS cnt FROM $wpdb->postmeta WHERE meta_key = '%s'", $meta_key );
     67        $sql      = $wpdb->prepare( "SELECT COUNT( post_id ) AS cnt FROM $wpdb->postmeta WHERE meta_key = '%s'", $meta_key );
    6968
    7069        $result = $wpdb->get_results( $sql );
    7170
    72         if ( !empty( $result ) )
     71        if ( ! empty( $result ) ) {
    7372            $count = intval( $result[0]->cnt );
     73        }
    7474
    7575        // Unset to save memory.
     
    9292        $hashtable = array();
    9393
    94         $limit = 100;
     94        $limit  = 100;
    9595        $offset = 0;
    9696
    9797        // Grab all comments in chunks
    9898        do {
    99             $sql = $wpdb->prepare( "SELECT comment_ID, comment_agent FROM $wpdb->comments LIMIT %d,%d", $offset, $limit );
     99            $sql     = $wpdb->prepare( "SELECT comment_ID, comment_agent FROM $wpdb->comments LIMIT %d,%d", $offset, $limit );
    100100            $results = $wpdb->get_results( $sql );
    101101
     
    103103            $offset = ( $limit + $offset );
    104104
    105             if ( !empty( $results ) ) {
     105            if ( ! empty( $results ) ) {
    106106                foreach ( $results as $r ) {
    107107                    // Explode comment_agent key
    108108                    list ( $ca_bid, $source_comment_id ) = explode( '-', $r->comment_agent );
    109                     $source_comment_id = intval( $source_comment_id );
     109                    $source_comment_id                   = intval( $source_comment_id );
    110110
    111111                    // Check if this comment came from this blog
    112112                    if ( $bid == $ca_bid ) {
    113                         $hashtable[$source_comment_id] = intval( $r->comment_ID );
     113                        $hashtable[ $source_comment_id ] = intval( $r->comment_ID );
    114114                    }
    115115                }
     
    124124
    125125    /**
    126      *
    127126     * @param int $blog_id
    128127     * @return int|void
     
    133132        } else {
    134133            $blog = 'http://' . preg_replace( '#^https?://#', '', $blog_id );
    135             if ( ( !$parsed = parse_url( $blog ) ) || empty( $parsed['host'] ) ) {
     134            if ( ( ! $parsed = parse_url( $blog ) ) || empty( $parsed['host'] ) ) {
    136135                fwrite( STDERR, "Error: can not determine blog_id from $blog_id\n" );
    137136                exit();
     
    140139                $parsed['path'] = '/';
    141140            }
    142             $blogs = get_sites( array( 'domain' => $parsed['host'], 'number' => 1, 'path' => $parsed['path'] ) );
     141            $blogs = get_sites(
     142                array(
     143                    'domain' => $parsed['host'],
     144                    'number' => 1,
     145                    'path'   => $parsed['path'],
     146                )
     147            );
    143148            if ( ! $blogs ) {
    144149                fwrite( STDERR, "Error: Could not find blog\n" );
    145150                exit();
    146151            }
    147             $blog = array_shift( $blogs );
     152            $blog    = array_shift( $blogs );
    148153            $blog_id = (int) $blog->blog_id;
    149154        }
    150155
    151156        if ( function_exists( 'is_multisite' ) ) {
    152             if ( is_multisite() )
     157            if ( is_multisite() ) {
    153158                switch_to_blog( $blog_id );
     159            }
    154160        }
    155161
     
    158164
    159165    /**
    160      *
    161166     * @param int $user_id
    162167     * @return int|void
     
    169174        }
    170175
    171         if ( !$user_id || !wp_set_current_user( $user_id ) ) {
     176        if ( ! $user_id || ! wp_set_current_user( $user_id ) ) {
    172177            fwrite( STDERR, "Error: can not find user\n" );
    173178            exit();
     
    202207
    203208        $headers = array();
    204         $args = array();
    205         if ( true === $head )
     209        $args    = array();
     210        if ( true === $head ) {
    206211            $args['method'] = 'HEAD';
    207         if ( !empty( $username ) && !empty( $password ) )
     212        }
     213        if ( ! empty( $username ) && ! empty( $password ) ) {
    208214            $headers['Authorization'] = 'Basic ' . base64_encode( "$username:$password" );
     215        }
    209216
    210217        $args['headers'] = $headers;
     
    279286
    280287    $last_arg = null;
    281     $return = null;
     288    $return   = null;
    282289
    283290    $il = sizeof( $args );
    284291
    285292    for ( $i = 1, $il; $i < $il; $i++ ) {
    286         if ( (bool) preg_match( "/^--(.+)/", $args[$i], $match ) ) {
    287             $parts = explode( "=", $match[1] );
    288             $key = preg_replace( "/[^a-z0-9]+/", "", $parts[0] );
     293        if ( (bool) preg_match( '/^--(.+)/', $args[ $i ], $match ) ) {
     294            $parts = explode( '=', $match[1] );
     295            $key   = preg_replace( '/[^a-z0-9]+/', '', $parts[0] );
    289296
    290297            if ( isset( $parts[1] ) ) {
    291                 $out[$key] = $parts[1];
     298                $out[ $key ] = $parts[1];
    292299            } else {
    293                 $out[$key] = true;
     300                $out[ $key ] = true;
    294301            }
    295302
    296303            $last_arg = $key;
    297         } elseif ( (bool) preg_match( "/^-([a-zA-Z0-9]+)/", $args[$i], $match ) ) {
     304        } elseif ( (bool) preg_match( '/^-([a-zA-Z0-9]+)/', $args[ $i ], $match ) ) {
    298305            for ( $j = 0, $jl = strlen( $match[1] ); $j < $jl; $j++ ) {
    299                 $key = $match[1]{$j};
    300                 $out[$key] = true;
     306                $key         = $match[1]{$j};
     307                $out[ $key ] = true;
    301308            }
    302309
    303310            $last_arg = $key;
    304311        } elseif ( $last_arg !== null ) {
    305             $out[$last_arg] = $args[$i];
     312            $out[ $last_arg ] = $args[ $i ];
    306313        }
    307314    }
    308315
    309316    // Check array for specified param
    310     if ( isset( $out[$param] ) ) {
     317    if ( isset( $out[ $param ] ) ) {
    311318        // Set return value
    312         $return = $out[$param];
     319        $return = $out[ $param ];
    313320    }
    314321
    315322    // Check for missing required param
    316     if ( !isset( $out[$param] ) && $required ) {
     323    if ( ! isset( $out[ $param ] ) && $required ) {
    317324        // Display message and exit
    318325        echo "\"$param\" parameter is required but was not specified\n";
Note: See TracChangeset for help on using the changeset viewer.