Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 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-includes/class.wp-dependencies.php

    r41162 r42343  
    9797
    9898        foreach ( $this->to_do as $key => $handle ) {
    99             if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) {
     99            if ( ! in_array( $handle, $this->done, true ) && isset( $this->registered[ $handle ] ) ) {
    100100                /*
    101101                 * Attempt to process the item. If successful,
     
    104104                 * Unset the item from the to_do array.
    105105                 */
    106                 if ( $this->do_item( $handle, $group ) )
     106                if ( $this->do_item( $handle, $group ) ) {
    107107                    $this->done[] = $handle;
    108 
    109                 unset( $this->to_do[$key] );
     108                }
     109
     110                unset( $this->to_do[ $key ] );
    110111            }
    111112        }
     
    123124     */
    124125    public function do_item( $handle ) {
    125         return isset($this->registered[$handle]);
     126        return isset( $this->registered[ $handle ] );
    126127    }
    127128
     
    142143     */
    143144    public function all_deps( $handles, $recursion = false, $group = false ) {
    144         if ( !$handles = (array) $handles )
    145             return false;
     145        if ( ! $handles = (array) $handles ) {
     146            return false;
     147        }
    146148
    147149        foreach ( $handles as $handle ) {
    148             $handle_parts = explode('?', $handle);
    149             $handle = $handle_parts[0];
    150             $queued = in_array($handle, $this->to_do, true);
    151 
    152             if ( in_array($handle, $this->done, true) ) // Already done
     150            $handle_parts = explode( '?', $handle );
     151            $handle       = $handle_parts[0];
     152            $queued       = in_array( $handle, $this->to_do, true );
     153
     154            if ( in_array( $handle, $this->done, true ) ) { // Already done
    153155                continue;
     156            }
    154157
    155158            $moved     = $this->set_group( $handle, $recursion, $group );
    156159            $new_group = $this->groups[ $handle ];
    157160
    158             if ( $queued && !$moved ) // already queued and in the right group
     161            if ( $queued && ! $moved ) { // already queued and in the right group
    159162                continue;
     163            }
    160164
    161165            $keep_going = true;
    162             if ( !isset($this->registered[$handle]) )
     166            if ( ! isset( $this->registered[ $handle ] ) ) {
    163167                $keep_going = false; // Item doesn't exist.
    164             elseif ( $this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered)) )
     168            } elseif ( $this->registered[ $handle ]->deps && array_diff( $this->registered[ $handle ]->deps, array_keys( $this->registered ) ) ) {
    165169                $keep_going = false; // Item requires dependencies that don't exist.
    166             elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true, $new_group ) )
     170            } elseif ( $this->registered[ $handle ]->deps && ! $this->all_deps( $this->registered[ $handle ]->deps, true, $new_group ) ) {
    167171                $keep_going = false; // Item requires dependencies that don't exist.
     172            }
    168173
    169174            if ( ! $keep_going ) { // Either item or its dependencies don't exist.
    170                 if ( $recursion )
     175                if ( $recursion ) {
    171176                    return false; // Abort this branch.
    172                 else
     177                } else {
    173178                    continue; // We're at the top level. Move on to the next one.
    174             }
    175 
    176             if ( $queued ) // Already grabbed it and its dependencies.
     179                }
     180            }
     181
     182            if ( $queued ) { // Already grabbed it and its dependencies.
    177183                continue;
    178 
    179             if ( isset($handle_parts[1]) )
    180                 $this->args[$handle] = $handle_parts[1];
     184            }
     185
     186            if ( isset( $handle_parts[1] ) ) {
     187                $this->args[ $handle ] = $handle_parts[1];
     188            }
    181189
    182190            $this->to_do[] = $handle;
     
    205213     */
    206214    public function add( $handle, $src, $deps = array(), $ver = false, $args = null ) {
    207         if ( isset($this->registered[$handle]) )
    208             return false;
    209         $this->registered[$handle] = new _WP_Dependency( $handle, $src, $deps, $ver, $args );
     215        if ( isset( $this->registered[ $handle ] ) ) {
     216            return false;
     217        }
     218        $this->registered[ $handle ] = new _WP_Dependency( $handle, $src, $deps, $ver, $args );
    210219        return true;
    211220    }
     
    224233     */
    225234    public function add_data( $handle, $key, $value ) {
    226         if ( !isset( $this->registered[$handle] ) )
    227             return false;
    228 
    229         return $this->registered[$handle]->add_data( $key, $value );
     235        if ( ! isset( $this->registered[ $handle ] ) ) {
     236            return false;
     237        }
     238
     239        return $this->registered[ $handle ]->add_data( $key, $value );
    230240    }
    231241
     
    242252     */
    243253    public function get_data( $handle, $key ) {
    244         if ( !isset( $this->registered[$handle] ) )
    245             return false;
    246 
    247         if ( !isset( $this->registered[$handle]->extra[$key] ) )
    248             return false;
    249 
    250         return $this->registered[$handle]->extra[$key];
     254        if ( ! isset( $this->registered[ $handle ] ) ) {
     255            return false;
     256        }
     257
     258        if ( ! isset( $this->registered[ $handle ]->extra[ $key ] ) ) {
     259            return false;
     260        }
     261
     262        return $this->registered[ $handle ]->extra[ $key ];
    251263    }
    252264
     
    261273     */
    262274    public function remove( $handles ) {
    263         foreach ( (array) $handles as $handle )
    264             unset($this->registered[$handle]);
     275        foreach ( (array) $handles as $handle ) {
     276            unset( $this->registered[ $handle ] );
     277        }
    265278    }
    266279
     
    280293    public function enqueue( $handles ) {
    281294        foreach ( (array) $handles as $handle ) {
    282             $handle = explode('?', $handle);
    283             if ( !in_array($handle[0], $this->queue) && isset($this->registered[$handle[0]]) ) {
     295            $handle = explode( '?', $handle );
     296            if ( ! in_array( $handle[0], $this->queue ) && isset( $this->registered[ $handle[0] ] ) ) {
    284297                $this->queue[] = $handle[0];
    285                 if ( isset($handle[1]) )
    286                     $this->args[$handle[0]] = $handle[1];
     298                if ( isset( $handle[1] ) ) {
     299                    $this->args[ $handle[0] ] = $handle[1];
     300                }
    287301            }
    288302        }
     
    302316    public function dequeue( $handles ) {
    303317        foreach ( (array) $handles as $handle ) {
    304             $handle = explode('?', $handle);
    305             $key = array_search($handle[0], $this->queue);
     318            $handle = explode( '?', $handle );
     319            $key    = array_search( $handle[0], $this->queue );
    306320            if ( false !== $key ) {
    307                 unset($this->queue[$key]);
    308                 unset($this->args[$handle[0]]);
     321                unset( $this->queue[ $key ] );
     322                unset( $this->args[ $handle[0] ] );
    309323            }
    310324        }
     
    348362    public function query( $handle, $list = 'registered' ) {
    349363        switch ( $list ) {
    350             case 'registered' :
     364            case 'registered':
    351365            case 'scripts': // back compat
    352                 if ( isset( $this->registered[ $handle ] ) )
     366                if ( isset( $this->registered[ $handle ] ) ) {
    353367                    return $this->registered[ $handle ];
     368                }
    354369                return false;
    355370
    356             case 'enqueued' :
    357             case 'queue' :
     371            case 'enqueued':
     372            case 'queue':
    358373                if ( in_array( $handle, $this->queue ) ) {
    359374                    return true;
     
    361376                return $this->recurse_deps( $this->queue, $handle );
    362377
    363             case 'to_do' :
     378            case 'to_do':
    364379            case 'to_print': // back compat
    365380                return in_array( $handle, $this->to_do );
    366381
    367             case 'done' :
     382            case 'done':
    368383            case 'printed': // back compat
    369384                return in_array( $handle, $this->done );
Note: See TracChangeset for help on using the changeset viewer.