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-includes/class-wp-tax-query.php

    r41688 r42343  
    4848         * @var string
    4949         */
    50         private static $no_results = array( 'join' => array( '' ), 'where' => array( '0 = 1' ) );
     50        private static $no_results = array(
     51                'join'  => array( '' ),
     52                'where' => array( '0 = 1' ),
     53        );
    5154
    5255        /**
    … …  
    136139
    137140                $defaults = array(
    138                         'taxonomy' => '',
    139                         'terms' => array(),
    140                         'field' => 'term_id',
    141                         'operator' => 'IN',
     141                        'taxonomy'         => '',
     142                        'terms'            => array(),
     143                        'field'            => 'term_id',
     144                        'operator'         => 'IN',
    142145                        'include_children' => true,
    143146                );
    … …  
    147150                                $cleaned_query['relation'] = $this->sanitize_relation( $query );
    148151
    149                         // First-order clause.
     152                                // First-order clause.
    150153                        } elseif ( self::is_first_order_clause( $query ) ) {
    151154
    152                                 $cleaned_clause = array_merge( $defaults, $query );
     155                                $cleaned_clause          = array_merge( $defaults, $query );
    153156                                $cleaned_clause['terms'] = (array) $cleaned_clause['terms'];
    154                                 $cleaned_query[] = $cleaned_clause;
     157                                $cleaned_query[]         = $cleaned_clause;
    155158
    156159                                /*
    … …  
    177180                                }
    178181
    179                         // Otherwise, it's a nested query, so we recurse.
     182                                // Otherwise, it's a nested query, so we recurse.
    180183                        } elseif ( is_array( $query ) ) {
    181184                                $cleaned_subquery = $this->sanitize_query( $query );
    … …  
    248251         */
    249252        public function get_sql( $primary_table, $primary_id_column ) {
    250                 $this->primary_table = $primary_table;
     253                $this->primary_table     = $primary_table;
    251254                $this->primary_id_column = $primary_id_column;
    252255
    … …  
    275278                 */
    276279                $queries = $this->queries;
    277                 $sql = $this->get_sql_for_query( $queries );
     280                $sql     = $this->get_sql_for_query( $queries );
    278281
    279282                if ( ! empty( $sql['where'] ) ) {
    … …  
    315318                $indent = '';
    316319                for ( $i = 0; $i < $depth; $i++ ) {
    317                         $indent .= "  ";
     320                        $indent .= '  ';
    318321                }
    319322
    … …  
    337340
    338341                                        $sql_chunks['join'] = array_merge( $sql_chunks['join'], $clause_sql['join'] );
    339                                 // This is a subquery, so we recurse.
     342                                        // This is a subquery, so we recurse.
    340343                                } else {
    341344                                        $clause_sql = $this->get_sql_for_query( $clause, $depth + 1 );
    … …  
    400403                }
    401404
    402                 $terms = $clause['terms'];
     405                $terms    = $clause['terms'];
    403406                $operator = strtoupper( $clause['operator'] );
    404407
    … …  
    417420                        $alias = $this->find_compatible_table_alias( $clause, $parent_query );
    418421                        if ( false === $alias ) {
    419                                 $i = count( $this->table_aliases );
     422                                $i     = count( $this->table_aliases );
    420423                                $alias = $i ? 'tt' . $i : $wpdb->term_relationships;
    421424
    … …  
    430433                                $join .= " ON ($this->primary_table.$this->primary_id_column = $alias.object_id)";
    431434                        }
    432 
    433435
    434436                        $where = "$alias.term_taxonomy_id $operator ($terms)";
    … …  
    467469                } elseif ( 'NOT EXISTS' === $operator || 'EXISTS' === $operator ) {
    468470
    469                         $where = $wpdb->prepare( "$operator (
     471                        $where = $wpdb->prepare(
     472                                "$operator (
    470473                                SELECT 1
    471474                                FROM $wpdb->term_relationships
    … …  
    474477                                WHERE $wpdb->term_taxonomy.taxonomy = %s
    475478                                AND $wpdb->term_relationships.object_id = $this->primary_table.$this->primary_id_column
    476                         )", $clause['taxonomy'] );
     479                        )", $clause['taxonomy']
     480                        );
    477481
    478482                }
    … …  
    562566                        $this->transform_query( $query, 'term_id' );
    563567
    564                         if ( is_wp_error( $query ) )
     568                        if ( is_wp_error( $query ) ) {
    565569                                return;
     570                        }
    566571
    567572                        $children = array();
    568573                        foreach ( $query['terms'] as $term ) {
    569                                 $children = array_merge( $children, get_term_children( $term, $query['taxonomy'] ) );
     574                                $children   = array_merge( $children, get_term_children( $term, $query['taxonomy'] ) );
    570575                                $children[] = $term;
    571576                        }
    … …  
    591596         */
    592597        public function transform_query( &$query, $resulting_field ) {
    593                 if ( empty( $query['terms'] ) )
     598                if ( empty( $query['terms'] ) ) {
    594599                        return;
    595 
    596                 if ( $query['field'] == $resulting_field )
     600                }
     601
     602                if ( $query['field'] == $resulting_field ) {
    597603                        return;
     604                }
    598605
    599606                $resulting_field = sanitize_key( $resulting_field );
Note: See TracChangeset for help on using the changeset viewer.