Skip to content

Commit 0e06d70

Browse files
committed
Consistently use short arrays
1 parent 677a3ea commit 0e06d70

11 files changed

+75
-75
lines changed

inc/authentication/namespace.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ function create_invalid_token_error( $token ) {
158158
return new WP_Error(
159159
'oauth2.authentication.attempt_authentication.invalid_token',
160160
__( 'Supplied token is invalid.', 'oauth2' ),
161-
array(
161+
[
162162
'status' => \WP_Http::FORBIDDEN,
163163
'token' => $token,
164-
)
164+
]
165165
);
166166
}

inc/class-client.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public function check_redirect_uri( $uri ) {
186186
}
187187

188188
// Check all components except query and fragment
189-
$parts = array( 'scheme', 'host', 'port', 'user', 'pass', 'path' );
189+
$parts = [ 'scheme', 'host', 'port', 'user', 'pass', 'path' ];
190190
$valid = true;
191191
foreach ( $parts as $part ) {
192192
if ( isset( $registered[ $part ] ) !== isset( $supplied[ $part ] ) ) {
@@ -279,18 +279,18 @@ public function issue_token( WP_User $user ) {
279279
* @return static|null Token if ID is found, null otherwise.
280280
*/
281281
public static function get_by_id( $id ) {
282-
$args = array(
282+
$args = [
283283
'post_type' => static::POST_TYPE,
284284
'post_status' => 'publish',
285285
'posts_per_page' => 1,
286286
'no_found_rows' => true,
287-
'meta_query' => array(
288-
array(
287+
'meta_query' => [
288+
[
289289
'key' => static::CLIENT_ID_KEY,
290290
'value' => $id,
291-
),
292-
),
293-
);
291+
],
292+
],
293+
];
294294
$query = new WP_Query( $args );
295295
if ( empty( $query->posts ) ) {
296296
return null;
@@ -322,25 +322,25 @@ public static function get_by_post_id( $id ) {
322322
* @return WP_Error|Client Client instance on success, error otherwise.
323323
*/
324324
public static function create( $data ) {
325-
$post_data = array(
325+
$post_data = [
326326
'post_type' => static::POST_TYPE,
327327
'post_title' => $data['name'],
328328
'post_content' => $data['description'],
329329
'post_status' => 'draft',
330-
);
330+
];
331331

332332
$post_id = wp_insert_post( wp_slash( $post_data ), true );
333333
if ( is_wp_error( $post_id ) ) {
334334
return $post_id;
335335
}
336336

337337
// Generate ID and secret.
338-
$meta = array(
338+
$meta = [
339339
static::REDIRECT_URI_KEY => $data['meta']['callback'],
340340
static::TYPE_KEY => $data['meta']['type'],
341341
static::CLIENT_ID_KEY => wp_generate_password( static::CLIENT_ID_LENGTH, false ),
342342
static::CLIENT_SECRET_KEY => wp_generate_password( static::CLIENT_SECRET_LENGTH, false ),
343-
);
343+
];
344344

345345
foreach ( $meta as $key => $value ) {
346346
$result = update_post_meta( $post_id, wp_slash( $key ), wp_slash( $value ) );
@@ -361,22 +361,22 @@ public static function create( $data ) {
361361
* @return WP_Error|Client Client instance on success, error otherwise.
362362
*/
363363
public function update( $data ) {
364-
$post_data = array(
364+
$post_data = [
365365
'ID' => $this->get_post_id(),
366366
'post_type' => static::POST_TYPE,
367367
'post_title' => $data['name'],
368368
'post_content' => $data['description'],
369-
);
369+
];
370370

371371
$post_id = wp_update_post( wp_slash( $post_data ), true );
372372
if ( is_wp_error( $post_id ) ) {
373373
return $post_id;
374374
}
375375

376-
$meta = array(
376+
$meta = [
377377
static::REDIRECT_URI_KEY => $data['meta']['callback'],
378378
static::TYPE_KEY => $data['meta']['type'],
379-
);
379+
];
380380

381381
foreach ( $meta as $key => $value ) {
382382
update_post_meta( $post_id, wp_slash( $key ), wp_slash( $value ) );
@@ -402,10 +402,10 @@ public function delete() {
402402
* @return bool|WP_Error True if client was updated, error otherwise.
403403
*/
404404
public function approve() {
405-
$data = array(
405+
$data = [
406406
'ID' => $this->get_post_id(),
407407
'post_status' => 'publish',
408-
);
408+
];
409409
$result = wp_update_post( wp_slash( $data ), true );
410410
return is_wp_error( $result ) ? $result : true;
411411
}
@@ -414,25 +414,25 @@ public function approve() {
414414
* Register the underlying post type.
415415
*/
416416
public static function register_type() {
417-
register_post_type( static::POST_TYPE, array(
417+
register_post_type( static::POST_TYPE, [
418418
'public' => false,
419419
'hierarchical' => true,
420-
'capability_type' => array(
420+
'capability_type' => [
421421
'oauth2_client',
422422
'oauth2_clients',
423-
),
424-
'capabilities' => array(
423+
],
424+
'capabilities' => [
425425
'edit_posts' => 'edit_users',
426426
'edit_others_posts' => 'edit_users',
427427
'publish_posts' => 'edit_users',
428-
),
429-
'supports' => array(
428+
],
429+
'supports' => [
430430
'title',
431431
'editor',
432432
'revisions',
433433
'author',
434434
'thumbnail',
435-
),
436-
));
435+
],
436+
] );
437437
}
438438
}

inc/class-scopes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Scopes {
66
protected $capabilities;
77

88
public function __construct() {
9-
$this->capabilities = array();
9+
$this->capabilities = [];
1010
}
1111

1212
public function register( $id, $capabilities ) {

inc/endpoints/class-authorization.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Authorization {
1313
* Register required actions and filters
1414
*/
1515
public function register_hooks() {
16-
add_action( 'login_form_' . static::LOGIN_ACTION, array( $this, 'handle_request' ) );
16+
add_action( 'login_form_' . static::LOGIN_ACTION, [ $this, 'handle_request' ] );
1717
}
1818

1919
public function handle_request() {

inc/endpoints/class-token.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212
*/
1313
class Token {
1414
public function register_routes() {
15-
register_rest_route( 'oauth2', '/access_token', array(
15+
register_rest_route( 'oauth2', '/access_token', [
1616
'methods' => 'POST',
17-
'callback' => array( $this, 'exchange_token' ),
18-
'args' => array(
19-
'grant_type' => array(
17+
'callback' => [ $this, 'exchange_token' ],
18+
'args' => [
19+
'grant_type' => [
2020
'required' => true,
2121
'type' => 'string',
22-
'validate_callback' => array( $this, 'validate_grant_type' ),
23-
),
24-
'client_id' => array(
22+
'validate_callback' => [ $this, 'validate_grant_type' ],
23+
],
24+
'client_id' => [
2525
'required' => true,
2626
'type' => 'string',
2727
'validate_callback' => 'rest_validate_request_arg',
28-
),
29-
'code' => array(
28+
],
29+
'code' => [
3030
'required' => true,
3131
'type' => 'string',
3232
'validate_callback' => 'rest_validate_request_arg',
33-
),
34-
),
35-
));
33+
],
34+
],
35+
] );
3636
}
3737

3838
/**
@@ -59,10 +59,10 @@ public function exchange_token( WP_REST_Request $request ) {
5959
return new WP_Error(
6060
'oauth2.endpoints.token.exchange_token.invalid_client',
6161
sprintf( __( 'Client ID %s is invalid.', 'oauth2' ), $request['client_id'] ),
62-
array(
62+
[
6363
'status' => WP_Http::BAD_REQUEST,
6464
'client_id' => $request['client_id'],
65-
)
65+
]
6666
);
6767
}
6868

@@ -96,10 +96,10 @@ public function exchange_token( WP_REST_Request $request ) {
9696
return $token;
9797
}
9898

99-
$data = array(
99+
$data = [
100100
'access_token' => $token->get_key(),
101101
'token_type' => 'bearer',
102-
);
102+
];
103103
return $data;
104104
}
105105
}

inc/tokens/class-access-token.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ public function revoke() {
6363
*/
6464
public static function get_by_id( $id ) {
6565
$key = static::META_PREFIX . $id;
66-
$args = array(
66+
$args = [
6767
'number' => 1,
6868
'count_total' => false,
69-
'meta_query' => array(
70-
array(
69+
'meta_query' => [
70+
[
7171
'key' => $key,
7272
'compare' => 'EXISTS',
73-
),
74-
),
75-
);
73+
],
74+
],
75+
];
7676
$query = new WP_User_Query( $args );
7777
$results = $query->get_results();
7878
if ( empty( $results ) ) {
@@ -124,10 +124,10 @@ public static function create( Client $client, WP_User $user ) {
124124
);
125125
}
126126

127-
$data = array(
127+
$data = [
128128
'client' => $client->get_id(),
129129
'created' => time(),
130-
);
130+
];
131131
$key = wp_generate_password( static::KEY_LENGTH, false );
132132
$meta_key = static::META_PREFIX . $key;
133133

inc/tokens/class-authorization-code.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,18 @@ public function get_expiration() {
114114
* @param array $args Other request arguments to validate.
115115
* @return bool|WP_Error True if valid, error describing problem otherwise.
116116
*/
117-
public function validate( $args = array() ) {
117+
public function validate( $args = [] ) {
118118
$expiration = $this->get_expiration();
119119
$now = time();
120120
if ( $expiration <= $now ) {
121121
return new WP_Error(
122122
'oauth2.tokens.authorization_code.validate.expired',
123123
__( 'Authorization code has expired.', 'oauth2' ),
124-
array(
124+
[
125125
'status' => WP_Http::BAD_REQUEST,
126126
'expiration' => $expiration,
127127
'time' => $now,
128-
)
128+
]
129129
);
130130
}
131131

@@ -164,11 +164,11 @@ public static function get_by_code( Client $client, $code ) {
164164
return new WP_Error(
165165
'oauth2.client.check_authorization_code.invalid_code',
166166
__( 'Authorization code is not valid for the specified client.', 'oauth2' ),
167-
array(
167+
[
168168
'status' => WP_Http::NOT_FOUND,
169169
'client' => $client->get_id(),
170170
'code' => $code,
171-
)
171+
]
172172
);
173173
}
174174

@@ -186,10 +186,10 @@ public static function get_by_code( Client $client, $code ) {
186186
public static function create( Client $client, WP_User $user ) {
187187
$code = wp_generate_password( static::KEY_LENGTH, false );
188188
$meta_key = static::KEY_PREFIX . $code;
189-
$data = array(
189+
$data = [
190190
'user' => (int) $user->ID,
191191
'expiration' => time() + static::MAX_AGE,
192-
);
192+
];
193193
$result = add_post_meta( $client->get_post_id(), wp_slash( $meta_key ), wp_slash( $data ), true );
194194
if ( ! $result ) {
195195
return new WP_Error(

inc/types/class-authorization-code.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ protected function handle_authorization_submission( $submit, Client $client, $da
3838
return $code;
3939
}
4040

41-
$redirect_args = array(
41+
$redirect_args = [
4242
'code' => $code->get_code(),
43-
);
43+
];
4444
break;
4545

4646
case 'cancel':
47-
$redirect_args = array(
47+
$redirect_args = [
4848
'error' => 'access_denied',
49-
);
49+
];
5050
break;
5151

5252
default:

inc/types/class-base.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ public function handle_authorisation() {
4444
return new WP_Error(
4545
'oauth2.types.authorization_code.handle_authorisation.invalid_client_id',
4646
sprintf( __( 'Client ID %s is invalid.', 'oauth2' ), $client_id ),
47-
array(
47+
[
4848
'status' => WP_Http::BAD_REQUEST,
4949
'client_id' => $client_id,
50-
)
50+
]
5151
);
5252
}
5353

inc/types/class-implicit.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ protected function handle_authorization_submission( $submit, Client $client, $da
3838
return $token;
3939
}
4040

41-
$redirect_args = array(
41+
$redirect_args = [
4242
'access_token' => $token->get_key(),
4343
'token_type' => 'bearer',
44-
);
44+
];
4545
break;
4646

4747
case 'cancel':
48-
$redirect_args = array(
48+
$redirect_args = [
4949
'error' => 'access_denied',
50-
);
50+
];
5151
break;
5252

5353
default:

0 commit comments

Comments
 (0)