fix: resolve PHPCS errors — remove short ternaries and fix docblock placement

- 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 <noreply@anthropic.com>
This commit is contained in:
Terence
2026-04-13 04:21:56 +07:00
parent b7da4f42b9
commit b92dc4b0d8
4 changed files with 16 additions and 9 deletions

View File

@@ -1,11 +1,12 @@
<?php <?php
declare( strict_types=1 );
/** /**
* Articles management partial. * Articles management partial.
* *
* @since 1.0.0 * @since 1.0.0
*/ */
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }

View File

@@ -1,11 +1,12 @@
<?php <?php
declare( strict_types=1 );
/** /**
* Analytics dashboard partial. * Analytics dashboard partial.
* *
* @since 1.0.0 * @since 1.0.0
*/ */
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }

View File

@@ -380,8 +380,8 @@ class Peptide_News_Cost_Tracker {
'total_cost' => (float) ( $totals->total_cost ?? 0 ), 'total_cost' => (float) ( $totals->total_cost ?? 0 ),
'total_tokens' => (int) ( $totals->total_tokens ?? 0 ), 'total_tokens' => (int) ( $totals->total_tokens ?? 0 ),
'total_requests' => (int) ( $totals->total_requests ?? 0 ), 'total_requests' => (int) ( $totals->total_requests ?? 0 ),
'by_model' => $by_model ?: array(), 'by_model' => ! empty( $by_model ) ? $by_model : array(),
'by_operation' => $by_operation ?: 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'; $table = $wpdb->prefix . 'peptide_news_llm_costs';
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return $wpdb->get_results( $results = $wpdb->get_results(
$wpdb->prepare( $wpdb->prepare(
"SELECT "SELECT
DATE(created_at) AS date, DATE(created_at) AS date,
@@ -413,7 +413,9 @@ class Peptide_News_Cost_Tracker {
$start_date . ' 00:00:00', $start_date . ' 00:00:00',
$end_date . ' 23:59:59' $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'; $table = $wpdb->prefix . 'peptide_news_llm_costs';
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return $wpdb->get_results( $results = $wpdb->get_results(
$wpdb->prepare( $wpdb->prepare(
"SELECT * FROM {$table} ORDER BY created_at DESC LIMIT %d", "SELECT * FROM {$table} ORDER BY created_at DESC LIMIT %d",
$limit $limit
) )
) ?: array(); );
return ! empty( $results ) ? $results : array();
} }
/** /**

View File

@@ -1,5 +1,4 @@
<?php <?php
declare( strict_types=1 );
/** /**
* Plugin Name: Peptide News Aggregator * Plugin Name: Peptide News Aggregator
* Plugin URI: https://github.com/peptiderepo/peptide-news-plugin * Plugin URI: https://github.com/peptiderepo/peptide-news-plugin
@@ -15,6 +14,8 @@ declare( strict_types=1 );
* Requires PHP: 7.4 * Requires PHP: 7.4
*/ */
declare( strict_types=1 );
// Abort if called directly. // Abort if called directly.
if ( ! defined( 'WPINC' ) ) { if ( ! defined( 'WPINC' ) ) {
die; die;