Commit bf72e6fe authored by Erick Hitter's avatar Erick Hitter
Browse files

PHPCS fixes

parent 10e2c836
<?php
/**
* Interact with plugin's REST API via WP-CLI
*
* @package a8c_Cron_Control
*/
namespace Automattic\WP\Cron_Control\CLI;
......@@ -10,9 +15,11 @@ class REST_API extends \WP_CLI_Command {
* Retrieve the current event queue
*
* @subcommand get-queue
* @param array $args Array of positional arguments.
* @param array $assoc_args Array of flags.
*/
public function get_queue( $args, $assoc_args ) {
// Build and make request
// Build and make request.
$queue_request = new \WP_REST_Request( 'POST', '/' . \Automattic\WP\Cron_Control\REST_API::API_NAMESPACE . '/' . \Automattic\WP\Cron_Control\REST_API::ENDPOINT_LIST );
$queue_request->add_header( 'Content-Type', 'application/json' );
$queue_request->set_body( wp_json_encode( array(
......@@ -21,32 +28,32 @@ class REST_API extends \WP_CLI_Command {
$queue_request = rest_do_request( $queue_request );
// Oh well
// Oh well.
if ( $queue_request->is_error() ) {
\WP_CLI::error( $queue_request->as_error()->get_error_message() );
}
// Get the decoded JSON object returned by the API
// Get the decoded JSON object returned by the API.
$queue_response = $queue_request->get_data();
// No events, nothing more to do
// No events, nothing more to do.
if ( empty( $queue_response['events'] ) ) {
\WP_CLI::warning( __( 'No events in the current queue', 'automattic-cron-control' ) );
return;
}
// Prepare items for display
// Prepare items for display.
$events_for_display = $this->format_events( $queue_response['events'] );
$total_events_to_display = count( $events_for_display );
\WP_CLI::log( sprintf( _n( 'Displaying one event', 'Displaying %s events', $total_events_to_display, 'automattic-cron-control' ), number_format_i18n( $total_events_to_display ) ) );
\WP_CLI::log( sprintf( _n( 'Displaying %s event', 'Displaying %s events', $total_events_to_display, 'automattic-cron-control' ), number_format_i18n( $total_events_to_display ) ) );
// And reformat
// And reformat.
$format = 'table';
if ( isset( $assoc_args['format'] ) ) {
if ( 'ids' === $assoc_args['format'] ) {
\WP_CLI::error( __( 'Invalid output format requested', 'automattic-cron-control' ) );
} else {
$format = $assoc_args[ 'format' ];
$format = $assoc_args['format'];
}
}
......@@ -64,8 +71,7 @@ class REST_API extends \WP_CLI_Command {
/**
* Format event data into something human-readable
*
* @param $events
*
* @param array $events Events to display.
* @return array
*/
private function format_events( $events ) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment