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/rest-api/class-wp-rest-server.php

    r42142 r42343  
    8989                        '/' => array(
    9090                                'callback' => array( $this, 'get_index' ),
    91                                 'methods' => 'GET',
    92                                 'args' => array(
     91                                'methods'  => 'GET',
     92                                'args'     => array(
    9393                                        'context' => array(
    9494                                                'default' => 'view',
     
    161161                foreach ( (array) $error->errors as $code => $messages ) {
    162162                        foreach ( (array) $messages as $message ) {
    163                                 $errors[] = array( 'code' => $code, 'message' => $message, 'data' => $error->get_error_data( $code ) );
     163                                $errors[] = array(
     164                                        'code'    => $code,
     165                                        'message' => $message,
     166                                        'data'    => $error->get_error_data( $code ),
     167                                );
    164168                        }
    165169                }
     
    261265                 * @param bool $rest_enabled Whether the REST API is enabled. Default true.
    262266                 */
    263                 apply_filters_deprecated( 'rest_enabled', array( true ), '4.7.0', 'rest_authentication_errors',
     267                apply_filters_deprecated(
     268                        'rest_enabled', array( true ), '4.7.0', 'rest_authentication_errors',
    264269                        __( 'The REST API can no longer be completely disabled, the rest_authentication_errors filter can be used to restrict access to the API, instead.' )
    265270                );
     
    399404                        if ( $json_error_message ) {
    400405                                $json_error_obj = new WP_Error( 'rest_encode_error', $json_error_message, array( 'status' => 500 ) );
    401                                 $result = $this->error_to_response( $json_error_obj );
    402                                 $result = wp_json_encode( $result->data[0] );
     406                                $result         = $this->error_to_response( $json_error_obj );
     407                                $result         = wp_json_encode( $result->data[0] );
    403408                        }
    404409
     
    472477
    473478                        foreach ( $items as $item ) {
    474                                 $attributes = $item['attributes'];
     479                                $attributes         = $item['attributes'];
    475480                                $attributes['href'] = $item['href'];
    476                                 $data[ $rel ][] = $attributes;
     481                                $data[ $rel ][]     = $attributes;
    477482                        }
    478483                }
     
    500505                }
    501506
    502                 $curies = $response->get_curies();
     507                $curies      = $response->get_curies();
    503508                $used_curies = array();
    504509
     
    516521                                preg_match( '!' . $rel_regex . '!', $rel, $matches );
    517522                                if ( $matches ) {
    518                                         $new_rel = $curie['name'] . ':' . $matches[1];
     523                                        $new_rel                       = $curie['name'] . ':' . $matches[1];
    519524                                        $used_curies[ $curie['name'] ] = $curie;
    520                                         $links[ $new_rel ] = $items;
     525                                        $links[ $new_rel ]             = $items;
    521526                                        unset( $links[ $rel ] );
    522527                                        break;
     
    653658                        $this->namespaces[ $namespace ] = array();
    654659
    655                         $this->register_route( $namespace, '/' . $namespace, array(
    656                                 array(
    657                                         'methods' => self::READABLE,
    658                                         'callback' => array( $this, 'get_namespace_index' ),
    659                                         'args' => array(
    660                                                 'namespace' => array(
    661                                                         'default' => $namespace,
    662                                                 ),
    663                                                 'context' => array(
    664                                                         'default' => 'view',
     660                        $this->register_route(
     661                                $namespace, '/' . $namespace, array(
     662                                        array(
     663                                                'methods'  => self::READABLE,
     664                                                'callback' => array( $this, 'get_namespace_index' ),
     665                                                'args'     => array(
     666                                                        'namespace' => array(
     667                                                                'default' => $namespace,
     668                                                        ),
     669                                                        'context'   => array(
     670                                                                'default' => 'view',
     671                                                        ),
    665672                                                ),
    666673                                        ),
    667                                 ),
    668                         ) );
     674                                )
     675                        );
    669676                }
    670677
    671678                // Associative to avoid double-registration.
    672679                $this->namespaces[ $namespace ][ $route ] = true;
    673                 $route_args['namespace'] = $namespace;
     680                $route_args['namespace']                  = $namespace;
    674681
    675682                if ( $override || empty( $this->endpoints[ $route ] ) ) {
     
    757764
    758765                                foreach ( $methods as $method ) {
    759                                         $method = strtoupper( trim( $method ) );
     766                                        $method                        = strtoupper( trim( $method ) );
    760767                                        $handler['methods'][ $method ] = true;
    761768                                }
     
    839846
    840847                        foreach ( $handlers as $handler ) {
    841                                 $callback  = $handler['callback'];
     848                                $callback = $handler['callback'];
    842849                                $response = null;
    843850
     
    10641071                }
    10651072
    1066                 $routes = $this->namespaces[ $namespace ];
     1073                $routes    = $this->namespaces[ $namespace ];
    10671074                $endpoints = array_intersect_key( $this->get_routes(), $routes );
    10681075
    1069                 $data = array(
     1076                $data     = array(
    10701077                        'namespace' => $namespace,
    1071                         'routes' => $this->get_data_for_routes( $endpoints, $request['context'] ),
     1078                        'routes'    => $this->get_data_for_routes( $endpoints, $request['context'] ),
    10721079                );
    10731080                $response = rest_ensure_response( $data );
     
    11471154                $data = array(
    11481155                        'namespace' => '',
    1149                         'methods' => array(),
     1156                        'methods'   => array(),
    11501157                        'endpoints' => array(),
    11511158                );
     
    11721179
    11731180                        $data['methods'] = array_merge( $data['methods'], array_keys( $callback['methods'] ) );
    1174                         $endpoint_data = array(
     1181                        $endpoint_data   = array(
    11751182                                'methods' => array_keys( $callback['methods'] ),
    11761183                        );
     
    13211328
    13221329                // CONTENT_* headers are not prefixed with HTTP_.
    1323                 $additional = array( 'CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true );
     1330                $additional = array(
     1331                        'CONTENT_LENGTH' => true,
     1332                        'CONTENT_MD5'    => true,
     1333                        'CONTENT_TYPE'   => true,
     1334                );
    13241335
    13251336                foreach ( $server as $key => $value ) {
Note: See TracChangeset for help on using the changeset viewer.