fix: resolve PHPCS errors and PHPUnit test failures for CI

Move declare(strict_types=1) after file-level docblock in all 12 class
files to satisfy WordPress Coding Standards docblock placement rule.
Fix multi-line function call formatting in class-psa-admin.php. Align
array double arrows and equals signs. Fix escaped backticks in
AIGeneratorTest heredoc that broke markdown fence stripping tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
peptiderepo
2026-04-13 21:38:04 +07:00
parent ed65b6ab90
commit 3bbf927510
14 changed files with 70 additions and 62 deletions

View File

@@ -1,5 +1,4 @@
<?php <?php
declare( strict_types=1 );
/** /**
* Admin settings page for Peptide Search AI. * Admin settings page for Peptide Search AI.
* *
@@ -12,6 +11,7 @@ declare( strict_types=1 );
* @see includes/class-psa-cost-tracker.php * @see includes/class-psa-cost-tracker.php
* @see includes/class-psa-post-type.php * @see includes/class-psa-post-type.php
*/ */
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
@@ -106,20 +106,28 @@ class PSA_Admin {
if ( 'migrate_categories' === $action && wp_verify_nonce( $nonce, 'psa_migrate_categories' ) ) { if ( 'migrate_categories' === $action && wp_verify_nonce( $nonce, 'psa_migrate_categories' ) ) {
self::run_category_migration(); self::run_category_migration();
add_action( 'admin_notices', function () { add_action(
'admin_notices',
function () {
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Category migration completed.', 'peptide-search-ai' ) . '</p></div>'; echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Category migration completed.', 'peptide-search-ai' ) . '</p></div>';
} ); }
);
} }
if ( 'reenrich' === $action && wp_verify_nonce( $nonce, 'psa_reenrich' ) ) { if ( 'reenrich' === $action && wp_verify_nonce( $nonce, 'psa_reenrich' ) ) {
$queued = self::queue_reenrichment(); $queued = self::queue_reenrichment();
add_action( 'admin_notices', function () use ( $queued ) { add_action(
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html( sprintf( 'admin_notices',
function () use ( $queued ) {
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html(
sprintf(
/* translators: %d = number of peptides queued */ /* translators: %d = number of peptides queued */
__( '%d peptides queued for re-enrichment.', 'peptide-search-ai' ), __( '%d peptides queued for re-enrichment.', 'peptide-search-ai' ),
$queued $queued
) ) . '</p></div>'; )
} ); ) . '</p></div>';
}
);
} }
} }

View File

@@ -1,5 +1,4 @@
<?php <?php
declare( strict_types=1 );
/** /**
* Handles AI content generation for new peptide entries. * Handles AI content generation for new peptide entries.
* *
@@ -13,6 +12,7 @@ declare( strict_types=1 );
* @see includes/class-psa-pubchem.php * @see includes/class-psa-pubchem.php
* @see includes/class-psa-post-type.php * @see includes/class-psa-post-type.php
*/ */
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;

View File

@@ -1,5 +1,4 @@
<?php <?php
declare( strict_types=1 );
/** /**
* Configuration constants for Peptide Search AI. * Configuration constants for Peptide Search AI.
* *
@@ -9,6 +8,7 @@ declare( strict_types=1 );
* *
* @package PeptideSearchAI * @package PeptideSearchAI
*/ */
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;

View File

@@ -1,5 +1,4 @@
<?php <?php
declare( strict_types=1 );
/** /**
* Tracks API usage costs and enforces monthly budget limits. * Tracks API usage costs and enforces monthly budget limits.
* *
@@ -10,6 +9,7 @@ declare( strict_types=1 );
* *
* @package PeptideSearchAI * @package PeptideSearchAI
*/ */
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;

View File

@@ -1,5 +1,4 @@
<?php <?php
declare( strict_types=1 );
/** /**
* Browsable peptide directory — REST endpoint, shortcode, and data formatting. * Browsable peptide directory — REST endpoint, shortcode, and data formatting.
* *
@@ -12,6 +11,7 @@ declare( strict_types=1 );
* @see includes/class-psa-search.php — existing search shortcode (separate from directory) * @see includes/class-psa-search.php — existing search shortcode (separate from directory)
* @see assets/js/psa-directory.js — frontend grid, filter, modal logic * @see assets/js/psa-directory.js — frontend grid, filter, modal logic
*/ */
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;

View File

@@ -1,5 +1,4 @@
<?php <?php
declare( strict_types=1 );
/** /**
* Handles encryption/decryption of sensitive data at rest. * Handles encryption/decryption of sensitive data at rest.
* *
@@ -11,6 +10,7 @@ declare( strict_types=1 );
* @see includes/class-psa-admin.php * @see includes/class-psa-admin.php
* @see includes/class-psa-ai-generator.php * @see includes/class-psa-ai-generator.php
*/ */
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;

View File

@@ -1,5 +1,4 @@
<?php <?php
declare( strict_types=1 );
/** /**
* Echo Knowledge Base article builder for generated peptide content. * Echo Knowledge Base article builder for generated peptide content.
* *
@@ -11,6 +10,7 @@ declare( strict_types=1 );
* @package PeptideSearchAI * @package PeptideSearchAI
* @see includes/class-psa-ai-generator.php * @see includes/class-psa-ai-generator.php
*/ */
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;

View File

@@ -1,5 +1,4 @@
<?php <?php
declare( strict_types=1 );
/** /**
* OpenRouter API communication layer. * OpenRouter API communication layer.
* *
@@ -12,6 +11,7 @@ declare( strict_types=1 );
* @see includes/class-psa-ai-generator.php * @see includes/class-psa-ai-generator.php
* @see includes/class-psa-cost-tracker.php * @see includes/class-psa-cost-tracker.php
*/ */
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;

View File

@@ -1,5 +1,4 @@
<?php <?php
declare( strict_types=1 );
/** /**
* Registers the Peptide custom post type, taxonomy, and meta fields. * Registers the Peptide custom post type, taxonomy, and meta fields.
* *
@@ -11,6 +10,7 @@ declare( strict_types=1 );
* @see includes/class-psa-ai-generator.php — auto-assigns category term after generation * @see includes/class-psa-ai-generator.php — auto-assigns category term after generation
* @see includes/class-psa-directory.php — reads taxonomy for directory filtering * @see includes/class-psa-directory.php — reads taxonomy for directory filtering
*/ */
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;

View File

@@ -1,5 +1,4 @@
<?php <?php
declare( strict_types=1 );
/** /**
* PubChem PUG REST API integration for molecular data enrichment. * PubChem PUG REST API integration for molecular data enrichment.
* *
@@ -10,6 +9,7 @@ declare( strict_types=1 );
* @package PeptideSearchAI * @package PeptideSearchAI
* @see includes/class-psa-ai-generator.php * @see includes/class-psa-ai-generator.php
*/ */
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;

View File

@@ -1,5 +1,4 @@
<?php <?php
declare( strict_types=1 );
/** /**
* Handles AJAX search, the [peptide_search] shortcode, and the REST API endpoint. * Handles AJAX search, the [peptide_search] shortcode, and the REST API endpoint.
* *
@@ -11,6 +10,7 @@ declare( strict_types=1 );
* @see includes/class-psa-ai-generator.php * @see includes/class-psa-ai-generator.php
* @see includes/class-psa-config.php * @see includes/class-psa-config.php
*/ */
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;

View File

@@ -1,5 +1,4 @@
<?php <?php
declare( strict_types=1 );
/** /**
* Custom template rendering for single peptide pages. * Custom template rendering for single peptide pages.
* *
@@ -11,6 +10,7 @@ declare( strict_types=1 );
* @see includes/class-psa-post-type.php * @see includes/class-psa-post-type.php
* @see includes/class-psa-directory.php — detail modal uses the same data via REST * @see includes/class-psa-directory.php — detail modal uses the same data via REST
*/ */
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;

View File

@@ -116,9 +116,9 @@ class AIGeneratorTest extends TestCase {
*/ */
public function test_parse_response_with_markdown_fences() { public function test_parse_response_with_markdown_fences() {
$response_text = <<<JSON $response_text = <<<JSON
\`\`\`json ```json
{"is_valid": true, "canonical_name": "Semaglutide", "reason": "GLP-1 agonist"} {"is_valid": true, "canonical_name": "Semaglutide", "reason": "GLP-1 agonist"}
\`\`\` ```
JSON; JSON;
$result = PSA_OpenRouter::parse_response( $response_text ); $result = PSA_OpenRouter::parse_response( $response_text );