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.


Built from https://develop.svn.wordpress.org/trunk@42343


git-svn-id: http://core.svn.wordpress.org/trunk@42172 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast
2017-11-30 23:11:00 +00:00
parent 62be7ad218
commit aaf99e6913
610 changed files with 55731 additions and 43711 deletions

View File

@@ -111,13 +111,13 @@ class WP_REST_Request implements ArrayAccess {
*/
public function __construct( $method = '', $route = '', $attributes = array() ) {
$this->params = array(
'URL' => array(),
'GET' => array(),
'POST' => array(),
'FILES' => array(),
'URL' => array(),
'GET' => array(),
'POST' => array(),
'FILES' => array(),
// See parse_json_params.
'JSON' => null,
'JSON' => null,
'defaults' => array(),
);
@@ -235,7 +235,7 @@ class WP_REST_Request implements ArrayAccess {
* @param string $value Header value, or list of values.
*/
public function set_header( $key, $value ) {
$key = $this->canonicalize_header_name( $key );
$key = $this->canonicalize_header_name( $key );
$value = (array) $value;
$this->headers[ $key ] = $value;
@@ -250,7 +250,7 @@ class WP_REST_Request implements ArrayAccess {
* @param string $value Header value, or list of values.
*/
public function add_header( $key, $value ) {
$key = $this->canonicalize_header_name( $key );
$key = $this->canonicalize_header_name( $key );
$value = (array) $value;
if ( ! isset( $this->headers[ $key ] ) ) {
@@ -368,7 +368,7 @@ class WP_REST_Request implements ArrayAccess {
* @param array $order {
* An array of types to check, in order of priority.
*
* @param string $type The type to check.
* @param string $type The type to check.
* }
* @param WP_REST_Request $this The request object.
*/
@@ -405,7 +405,7 @@ class WP_REST_Request implements ArrayAccess {
* @param mixed $value Parameter value.
*/
public function set_param( $key, $value ) {
$order = $this->get_parameter_order();
$order = $this->get_parameter_order();
$this->params[ $order[0] ][ $key ] = $value;
}
@@ -587,8 +587,8 @@ class WP_REST_Request implements ArrayAccess {
$this->body = $data;
// Enable lazy parsing.
$this->parsed_json = false;
$this->parsed_body = false;
$this->parsed_json = false;
$this->parsed_body = false;
$this->params['JSON'] = null;
}
@@ -650,7 +650,7 @@ class WP_REST_Request implements ArrayAccess {
'status' => WP_Http::BAD_REQUEST,
);
if ( function_exists( 'json_last_error' ) ) {
$error_data['json_error_code'] = json_last_error();
$error_data['json_error_code'] = json_last_error();
$error_data['json_error_message'] = json_last_error_msg();
}
@@ -802,7 +802,12 @@ class WP_REST_Request implements ArrayAccess {
}
if ( $invalid_params ) {
return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) );
return new WP_Error(
'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array(
'status' => 400,
'params' => $invalid_params,
)
);
}
return true;
@@ -824,7 +829,7 @@ class WP_REST_Request implements ArrayAccess {
}
$attributes = $this->get_attributes();
$required = array();
$required = array();
// No arguments set, skip validation.
if ( empty( $attributes['args'] ) ) {
@@ -840,7 +845,12 @@ class WP_REST_Request implements ArrayAccess {
}
if ( ! empty( $required ) ) {
return new WP_Error( 'rest_missing_callback_param', sprintf( __( 'Missing parameter(s): %s' ), implode( ', ', $required ) ), array( 'status' => 400, 'params' => $required ) );
return new WP_Error(
'rest_missing_callback_param', sprintf( __( 'Missing parameter(s): %s' ), implode( ', ', $required ) ), array(
'status' => 400,
'params' => $required,
)
);
}
/*
@@ -868,7 +878,12 @@ class WP_REST_Request implements ArrayAccess {
}
if ( $invalid_params ) {
return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) );
return new WP_Error(
'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array(
'status' => 400,
'params' => $invalid_params,
)
);
}
return true;
@@ -945,7 +960,7 @@ class WP_REST_Request implements ArrayAccess {
* @return WP_REST_Request|false WP_REST_Request object on success, false on failure.
*/
public static function from_url( $url ) {
$bits = parse_url( $url );
$bits = parse_url( $url );
$query_params = array();
if ( ! empty( $bits['query'] ) ) {
@@ -956,7 +971,7 @@ class WP_REST_Request implements ArrayAccess {
if ( get_option( 'permalink_structure' ) && 0 === strpos( $url, $api_root ) ) {
// Pretty permalinks on, and URL is under the API root.
$api_url_part = substr( $url, strlen( untrailingslashit( $api_root ) ) );
$route = parse_url( $api_url_part, PHP_URL_PATH );
$route = parse_url( $api_url_part, PHP_URL_PATH );
} elseif ( ! empty( $query_params['rest_route'] ) ) {
// ?rest_route=... set directly
$route = $query_params['rest_route'];