Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 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-scripts.php

    r41686 r42343  
    146146         * @param WP_Scripts $this WP_Scripts instance (passed by reference).
    147147         */
    148         do_action_ref_array( 'wp_default_scripts', array(&$this) );
     148        do_action_ref_array( 'wp_default_scripts', array( &$this ) );
    149149    }
    150150
     
    197197     */
    198198    public function print_extra_script( $handle, $echo = true ) {
    199         if ( !$output = $this->get_data( $handle, 'data' ) )
     199        if ( ! $output = $this->get_data( $handle, 'data' ) ) {
    200200            return;
    201 
    202         if ( !$echo )
     201        }
     202
     203        if ( ! $echo ) {
    203204            return $output;
     205        }
    204206
    205207        echo "<script type='text/javascript'>\n"; // CDATA and type='text/javascript' is not needed for HTML 5
     
    225227     */
    226228    public function do_item( $handle, $group = false ) {
    227         if ( !parent::do_item($handle) )
     229        if ( ! parent::do_item( $handle ) ) {
    228230            return false;
    229 
    230         if ( 0 === $group && $this->groups[$handle] > 0 ) {
     231        }
     232
     233        if ( 0 === $group && $this->groups[ $handle ] > 0 ) {
    231234            $this->in_footer[] = $handle;
    232235            return false;
    233236        }
    234237
    235         if ( false === $group && in_array($handle, $this->in_footer, true) )
     238        if ( false === $group && in_array( $handle, $this->in_footer, true ) ) {
    236239            $this->in_footer = array_diff( $this->in_footer, (array) $handle );
    237 
    238         $obj = $this->registered[$handle];
     240        }
     241
     242        $obj = $this->registered[ $handle ];
    239243
    240244        if ( null === $obj->ver ) {
     
    244248        }
    245249
    246         if ( isset($this->args[$handle]) )
    247             $ver = $ver ? $ver . '&amp;' . $this->args[$handle] : $this->args[$handle];
    248 
    249         $src = $obj->src;
     250        if ( isset( $this->args[ $handle ] ) ) {
     251            $ver = $ver ? $ver . '&amp;' . $this->args[ $handle ] : $this->args[ $handle ];
     252        }
     253
     254        $src         = $obj->src;
    250255        $cond_before = $cond_after = '';
    251256        $conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
     
    253258        if ( $conditional ) {
    254259            $cond_before = "<!--[if {$conditional}]>\n";
    255             $cond_after = "<![endif]-->\n";
     260            $cond_after  = "<![endif]-->\n";
    256261        }
    257262
    258263        $before_handle = $this->print_inline_script( $handle, 'before', false );
    259         $after_handle = $this->print_inline_script( $handle, 'after', false );
     264        $after_handle  = $this->print_inline_script( $handle, 'after', false );
    260265
    261266        if ( $before_handle ) {
     
    285290                $this->reset();
    286291            } elseif ( $this->in_default_dir( $srce ) && ! $conditional ) {
    287                 $this->print_code .= $this->print_extra_script( $handle, false );
    288                 $this->concat .= "$handle,";
     292                $this->print_code     .= $this->print_extra_script( $handle, false );
     293                $this->concat         .= "$handle,";
    289294                $this->concat_version .= "$handle$ver";
    290295                return true;
     
    316321        }
    317322
    318         if ( ! empty( $ver ) )
     323        if ( ! empty( $ver ) ) {
    319324            $src = add_query_arg( 'ver', $ver, $src );
     325        }
    320326
    321327        /** This filter is documented in wp-includes/class.wp-scripts.php */
    322328        $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
    323329
    324         if ( ! $src )
     330        if ( ! $src ) {
    325331            return true;
     332        }
    326333
    327334        $tag = "{$cond_before}{$before_handle}<script type='text/javascript' src='$src'></script>\n{$after_handle}{$cond_after}";
     
    412419     */
    413420    public function localize( $handle, $object_name, $l10n ) {
    414         if ( $handle === 'jquery' )
     421        if ( $handle === 'jquery' ) {
    415422            $handle = 'jquery-core';
    416 
    417         if ( is_array($l10n) && isset($l10n['l10n_print_after']) ) { // back compat, preserve the code in 'l10n_print_after' if present
     423        }
     424
     425        if ( is_array( $l10n ) && isset( $l10n['l10n_print_after'] ) ) { // back compat, preserve the code in 'l10n_print_after' if present
    418426            $after = $l10n['l10n_print_after'];
    419             unset($l10n['l10n_print_after']);
     427            unset( $l10n['l10n_print_after'] );
    420428        }
    421429
    422430        foreach ( (array) $l10n as $key => $value ) {
    423             if ( !is_scalar($value) )
     431            if ( ! is_scalar( $value ) ) {
    424432                continue;
    425 
    426             $l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8');
     433            }
     434
     435            $l10n[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
    427436        }
    428437
    429438        $script = "var $object_name = " . wp_json_encode( $l10n ) . ';';
    430439
    431         if ( !empty($after) )
     440        if ( ! empty( $after ) ) {
    432441            $script .= "\n$after;";
     442        }
    433443
    434444        $data = $this->get_data( $handle, 'data' );
    435445
    436         if ( !empty( $data ) )
     446        if ( ! empty( $data ) ) {
    437447            $script = "$data\n$script";
     448        }
    438449
    439450        return $this->add_data( $handle, 'data', $script );
     
    453464     */
    454465    public function set_group( $handle, $recursion, $group = false ) {
    455         if ( isset( $this->registered[$handle]->args ) && $this->registered[$handle]->args === 1 )
     466        if ( isset( $this->registered[ $handle ]->args ) && $this->registered[ $handle ]->args === 1 ) {
    456467            $grp = 1;
    457         else
     468        } else {
    458469            $grp = (int) $this->get_data( $handle, 'group' );
    459 
    460         if ( false !== $group && $grp > $group )
     470        }
     471
     472        if ( false !== $group && $grp > $group ) {
    461473            $grp = $group;
     474        }
    462475
    463476        return parent::set_group( $handle, $recursion, $grp );
     
    466479    /**
    467480     * Determines script dependencies.
    468     *
     481    *
    469482     * @since 2.1.0
    470483     *
     
    501514     */
    502515    public function do_head_items() {
    503         $this->do_items(false, 0);
     516        $this->do_items( false, 0 );
    504517        return $this->done;
    505518    }
     
    515528     */
    516529    public function do_footer_items() {
    517         $this->do_items(false, 1);
     530        $this->do_items( false, 1 );
    518531        return $this->done;
    519532    }
     
    550563     */
    551564    public function reset() {
    552         $this->do_concat = false;
    553         $this->print_code = '';
    554         $this->concat = '';
     565        $this->do_concat      = false;
     566        $this->print_code     = '';
     567        $this->concat         = '';
    555568        $this->concat_version = '';
    556         $this->print_html = '';
    557         $this->ext_version = '';
    558         $this->ext_handles = '';
     569        $this->print_html     = '';
     570        $this->ext_version    = '';
     571        $this->ext_handles    = '';
    559572    }
    560573}
Note: See TracChangeset for help on using the changeset viewer.