metrics = $metrics; } /** * @param array $run Smart Optimize run data. * @return array */ public function report( array $run = array() ) { $before = isset( $run['before'] ) && is_array( $run['before'] ) ? $run['before'] : array(); $after = isset( $run['after'] ) && is_array( $run['after'] ) ? $run['after'] : $this->metrics->snapshot(); $features = isset( $run['updated_features'] ) ? count( (array) $run['updated_features'] ) : 0; return array( 'generated_at' => time(), 'run_id' => isset( $run['id'] ) ? sanitize_text_field( $run['id'] ) : '', 'mode' => isset( $run['mode'] ) ? sanitize_key( $run['mode'] ) : '', 'status' => isset( $run['status'] ) ? sanitize_key( $run['status'] ) : 'not_started', 'before' => $before, 'after' => $after, 'delta' => array( 'health' => null ), 'summary' => array( 'headline' => sprintf( /* translators: %d: number of features configured. */ _n( '%d feature configured', '%d features configured', $features, 'nbh-performance' ), $features ), 'measurement_note' => __( 'This is local configuration and cache evidence, not a Lighthouse or real-user speed measurement.', 'nbh-performance' ), ), 'cache' => (array) get_option( 'nbh_performance_cache_stats', array() ), // The original JPEG/PNG files are preserved; source-byte savings are zero. 'image_savings' => 0, 'validation' => isset( $run['validation'] ) && is_array( $run['validation'] ) ? $run['validation'] : (array) get_option( 'nbh_performance_last_staging_validation', array() ), 'rollbacks' => array_slice( (array) get_option( 'nbh_performance_automatic_rollback_history', array() ), 0, 10 ), 'evidence' => array( 'baseline_available' => ! empty( $before ), 'source' => 'local_configuration', ), ); } }