From b92dc4b0d86f8b4d699a730d1dda2c7554750434 Mon Sep 17 00:00:00 2001 From: Terence Date: Mon, 13 Apr 2026 04:21:56 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20resolve=20PHPCS=20errors=20=E2=80=94=20r?= =?UTF-8?q?emove=20short=20ternaries=20and=20fix=20docblock=20placement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace 4 short ternary operators (?:) with explicit conditionals in Cost_Tracker - Move declare(strict_types=1) after file-level docblocks in 3 template files (PHPCS requires docblock immediately after opening PHP tag) Co-Authored-By: Claude Opus 4.6 --- admin/partials/articles-list.php | 3 ++- admin/partials/dashboard.php | 3 ++- includes/class-peptide-news-cost-tracker.php | 16 ++++++++++------ peptide-news-plugin.php | 3 ++- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/admin/partials/articles-list.php b/admin/partials/articles-list.php index c4021fd..c13b872 100755 --- a/admin/partials/articles-list.php +++ b/admin/partials/articles-list.php @@ -1,11 +1,12 @@ (float) ( $totals->total_cost ?? 0 ), 'total_tokens' => (int) ( $totals->total_tokens ?? 0 ), 'total_requests' => (int) ( $totals->total_requests ?? 0 ), - 'by_model' => $by_model ?: array(), - 'by_operation' => $by_operation ?: array(), + 'by_model' => ! empty( $by_model ) ? $by_model : array(), + 'by_operation' => ! empty( $by_operation ) ? $by_operation : array(), ); } @@ -399,7 +399,7 @@ class Peptide_News_Cost_Tracker { $table = $wpdb->prefix . 'peptide_news_llm_costs'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching - return $wpdb->get_results( + $results = $wpdb->get_results( $wpdb->prepare( "SELECT DATE(created_at) AS date, @@ -413,7 +413,9 @@ class Peptide_News_Cost_Tracker { $start_date . ' 00:00:00', $end_date . ' 23:59:59' ) - ) ?: array(); + ); + + return ! empty( $results ) ? $results : array(); } /** @@ -427,12 +429,14 @@ class Peptide_News_Cost_Tracker { $table = $wpdb->prefix . 'peptide_news_llm_costs'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching - return $wpdb->get_results( + $results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table} ORDER BY created_at DESC LIMIT %d", $limit ) - ) ?: array(); + ); + + return ! empty( $results ) ? $results : array(); } /** diff --git a/peptide-news-plugin.php b/peptide-news-plugin.php index 74503f9..8122ad9 100755 --- a/peptide-news-plugin.php +++ b/peptide-news-plugin.php @@ -1,5 +1,4 @@