Automattic\WooCommerce\Blueprint\ResultFormatters

CliResultFormatter::formatpublicWC 1.0

Format the results.

Method of the class: CliResultFormatter{}

No Hooks.

Returns

null. Nothing (null).

Usage

$CliResultFormatter = new CliResultFormatter();
$CliResultFormatter->format( $message_type );
$message_type(string)
The message type to format.
Default: 'debug'

CliResultFormatter::format() code WC 9.9.5

public function format( $message_type = 'debug' ) {
	$header = array( 'Step Processor', 'Type', 'Message' );
	$items  = array();

	foreach ( $this->results as $result ) {
		$step_name = $result->get_step_name();
		foreach ( $result->get_messages( $message_type ) as $message ) {
			$items[] = array(
				'Step Processor' => $step_name,
				'Type'           => $message['type'],
				'Message'        => $message['message'],
			);
		}
	}

	$format_items_exist = function_exists( '\WP_CLI\Utils\format_items' );

	if ( ! $format_items_exist ) {
		throw new \Exception( 'WP CLI Utils not found' );
	}

	format_items( 'table', $items, $header );
}