Skip to content

Commit 9d296af

Browse files
committed
👌 IMPROVE: General code cleanup
1 parent 84b2646 commit 9d296af

5 files changed

Lines changed: 46 additions & 22 deletions

File tree

benchpress.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ function benchpress_render_settings_page() {
241241
if ( version_compare( PHP_VERSION, '8.0', '>=' ) ) {
242242
echo '<tr><th>' . esc_html__( 'Enable Switch vs Match Benchmark', 'benchpress' ) . '</th>';
243243
echo '<td><input type="checkbox" name="benchpress_enable_switch_vs_match" ' . checked( 1, $enable_switch_vs_match, false ) . ' /></td></tr>';
244-
}
244+
}
245245
echo '<tr><th>' . esc_html__( 'Enable Transient vs Direct Query Benchmark', 'benchpress' ) . '</th>';
246246
echo '<td><input type="checkbox" name="benchpress_enable_transient_vs_query" ' . checked( 1, get_option( 'benchpress_enable_transient_vs_query', 1 ), false ) . ' /></td></tr>';
247247
echo '<tr><th>' . esc_html__( 'Enable Post Meta Access Benchmark', 'benchpress' ) . '</th>';
@@ -463,10 +463,9 @@ function benchpress_ajax_snapshot() {
463463
* This function verifies the AJAX nonce, deletes the specified snapshot
464464
* from the database, and returns a success or error message based on the result.
465465
*
466-
* @since 1.0.0
467-
*
468466
* @global wpdb $wpdb WordPress database abstraction object.
469467
*
468+
* @since 1.0.0
470469
* @return void
471470
*/
472471
function benchpress_delete_snapshot() {

classes/BenchPress_Snapshots_Table.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public function __construct() {
1616

1717
/**
1818
* Define columns for the Snapshots table.
19+
*
20+
* @since 1.0.0
21+
* @return array
1922
*/
2023
public function get_columns() {
2124
return [
@@ -27,6 +30,9 @@ public function get_columns() {
2730

2831
/**
2932
* Define sortable columns.
33+
*
34+
* @since 1.0.0
35+
* @return array
3036
*/
3137
public function get_sortable_columns() {
3238
return [
@@ -37,6 +43,9 @@ public function get_sortable_columns() {
3743

3844
/**
3945
* Prepare items for display in the Snapshots table.
46+
*
47+
* @since 1.0.0
48+
* @return void
4049
*/
4150
public function prepare_items() {
4251
global $wpdb;
@@ -61,15 +70,18 @@ public function prepare_items() {
6170
);
6271

6372
$total_items = $wpdb->get_var( "SELECT COUNT(id) FROM $table_name" );
64-
$this->set_pagination_args([
73+
$this->set_pagination_args( [
6574
'total_items' => $total_items,
6675
'per_page' => $per_page,
6776
'total_pages' => ceil( $total_items / $per_page ),
68-
]);
77+
] );
6978
}
7079

7180
/**
7281
* Default column renderer for displaying data.
82+
*
83+
* @since 1.0.0
84+
* @return mixed
7385
*/
7486
protected function column_default( $item, $column_name ) {
7587
switch ( $column_name ) {

classes/BenchPress_Table.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public function __construct() {
2323

2424
/**
2525
* Define table columns.
26-
*
26+
*
27+
* @since 1.0.0
2728
* @return array List of columns.
2829
*/
2930
public function get_columns() {
@@ -36,6 +37,9 @@ public function get_columns() {
3637

3738
/**
3839
* Prepare items for the table.
40+
*
41+
* @since 1.0.0
42+
* @return void
3943
*/
4044
public function prepare_items() {
4145
$benchmarks = benchpress_run_all_benchmarks();
@@ -50,6 +54,8 @@ public function prepare_items() {
5054
*
5155
* @param array $item Item data.
5256
* @param string $column_name Column name.
57+
*
58+
* @since 1.0.0
5359
* @return mixed Column output.
5460
*/
5561
public function column_default( $item, $column_name ) {
@@ -60,6 +66,9 @@ public function column_default( $item, $column_name ) {
6066
* Override the parent display_tablenav method to remove empty divs.
6167
*
6268
* @param string $which The position of the tablenav (top or bottom).
69+
*
70+
* @since 1.0.0
71+
* @return void
6372
*/
6473
public function display_tablenav( $which ) {
6574
// Do nothing.
@@ -68,6 +77,8 @@ public function display_tablenav( $which ) {
6877
/**
6978
* Override the parent get_bulk_actions method to remove bulk actions.
7079
*
80+
*
81+
* @since 1.0.0
7182
* @return array An empty array of bulk actions.
7283
*/
7384
public function get_bulk_actions() {
@@ -77,6 +88,8 @@ public function get_bulk_actions() {
7788
/**
7889
* Override pagination to prevent showing pagination controls.
7990
*
91+
*
92+
* @since 1.0.0
8093
* @return void
8194
*/
8295
public function pagination( $which ) {

includes/helper-functions.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
* @return array Benchmark data for WP_Query by ID.
1313
*/
1414
function benchpress_benchmark_wp_query_by_id() {
15-
// Retrieve settings
16-
$query_type = get_option( 'benchpress_query_type', 'single' );
17-
$post_id = get_option( 'benchpress_post_id', [] );
18-
$post_type = get_option( 'benchpress_post_type', 'post' );
19-
$post_count = get_option( 'benchpress_post_count', 5 );
20-
$taxonomy = get_option( 'benchpress_taxonomy', '' );
21-
$tax_terms = get_option( 'benchpress_tax_terms', '' );
22-
$orderby = get_option( 'benchpress_orderby', 'date' );
23-
$order = get_option( 'benchpress_order', 'ASC' );
24-
$iterations = get_option( 'benchpress_query_iterations', 1 );
15+
// Retrieve settings.
16+
$query_type = get_option( 'benchpress_query_type', 'single' );
17+
$post_id = get_option( 'benchpress_post_id', [] );
18+
$post_type = get_option( 'benchpress_post_type', 'post' );
19+
$post_count = get_option( 'benchpress_post_count', 5 );
20+
$taxonomy = get_option( 'benchpress_taxonomy', '' );
21+
$tax_terms = get_option( 'benchpress_tax_terms', '' );
22+
$orderby = get_option( 'benchpress_orderby', 'date' );
23+
$order = get_option( 'benchpress_order', 'ASC' );
24+
$iterations = get_option( 'benchpress_query_iterations', 1 );
2525

2626
$args = [
2727
'post_type' => $post_type,
@@ -90,7 +90,7 @@ function benchpress_benchmark_wp_query_by_id() {
9090
/**
9191
* Benchmark Array Merge Methods.
9292
*
93-
* @since 1.0.0
93+
* @since 1.0.0
9494
* @return array Benchmark data for array merge.
9595
*/
9696
function benchpress_benchmark_array_merge() {
@@ -226,10 +226,10 @@ function benchpress_benchmark_transient_vs_direct_query() {
226226
$loop_count
227227
);
228228

229-
// Measure execution time for direct query..
229+
// Measure execution time for direct query.
230230
$start_direct = microtime( true );
231231
$wpdb->get_results( $query );
232-
$end_direct = microtime( true );
232+
$end_direct = microtime( true );
233233
$direct_query_time = $end_direct - $start_direct;
234234

235235
// Measure execution time for transient caching.

includes/php-8.0-functions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ function benchpress_benchmark_switch_vs_match() {
5353
$faster_or_slower = $difference > 0 ? 'slower' : 'faster';
5454

5555
return [
56-
'name' => esc_html__( 'Switch vs Match', 'benchpress' ),
57-
'execution_time'=> round( abs( $difference ), 5 ),
58-
'description' => sprintf(
56+
'name' => esc_html__( 'Switch vs Match', 'benchpress' ),
57+
'execution_time' => round( abs( $difference ), 5 ),
58+
'description' => sprintf(
5959
esc_html__( 'The switch statement is %s by %s seconds compared to match.', 'benchpress' ),
6060
$faster_or_slower,
6161
round( abs( $difference ), 5 )

0 commit comments

Comments
 (0)