mirror of
https://hk.gh-proxy.com/https://github.com/wp-cli/profile-command.git
synced 2025-08-21 06:38:51 +08:00
Fix bottom of the table when there aren't any items displayed
The cells need to be filled in appropriately
This commit is contained in:
parent
e0af87e156
commit
a789b3ce34
2 changed files with 15 additions and 4 deletions
|
@ -28,3 +28,12 @@ Feature: Basic profile usage
|
||||||
"""
|
"""
|
||||||
Error: 'SAVEQUERIES' is defined as false, and must be true. Please check your wp-config.php
|
Error: 'SAVEQUERIES' is defined as false, and must be true. Please check your wp-config.php
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
Scenario: Profile a hook without any callbacks
|
||||||
|
Given a WP install
|
||||||
|
|
||||||
|
When I run `wp profile --hook=setup_theme --fields=callback,time`
|
||||||
|
Then STDOUT should be a table containing rows:
|
||||||
|
| callback | time |
|
||||||
|
| total | |
|
||||||
|
And STDERR should be empty
|
||||||
|
|
|
@ -60,16 +60,15 @@ class Formatter {
|
||||||
|
|
||||||
$table->setHeaders( $fields );
|
$table->setHeaders( $fields );
|
||||||
|
|
||||||
$totals = array(
|
$totals = array_fill( 0, count( $fields ), null );
|
||||||
'total',
|
$totals[0] = 'total';
|
||||||
);
|
|
||||||
foreach ( $items as $item ) {
|
foreach ( $items as $item ) {
|
||||||
$values = array_values( \WP_CLI\Utils\pick_fields( $item, $fields ) );
|
$values = array_values( \WP_CLI\Utils\pick_fields( $item, $fields ) );
|
||||||
foreach( $values as $i => $value ) {
|
foreach( $values as $i => $value ) {
|
||||||
if ( 0 === $i ) {
|
if ( 0 === $i ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( ! isset( $totals[ $i ] ) ) {
|
if ( null === $totals[ $i ] ) {
|
||||||
if ( stripos( $fields[ $i ], '_ratio' ) ) {
|
if ( stripos( $fields[ $i ], '_ratio' ) ) {
|
||||||
$totals[ $i ] = array();
|
$totals[ $i ] = array();
|
||||||
} else {
|
} else {
|
||||||
|
@ -90,6 +89,9 @@ class Formatter {
|
||||||
$table->addRow( $values );
|
$table->addRow( $values );
|
||||||
}
|
}
|
||||||
foreach( $totals as $i => $value ) {
|
foreach( $totals as $i => $value ) {
|
||||||
|
if ( null === $value ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ( stripos( $fields[ $i ], '_time' ) || 'time' === $fields[ $i ] ) {
|
if ( stripos( $fields[ $i ], '_time' ) || 'time' === $fields[ $i ] ) {
|
||||||
$totals[ $i ] = round( $value, 4 ) . 's';
|
$totals[ $i ] = round( $value, 4 ) . 's';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue