style: auto-fix PHPCS violations via phpcbf

This commit is contained in:
peptiderepo
2026-06-16 15:26:16 +00:00
parent 08d7696444
commit b9158d7dca
45 changed files with 1018 additions and 658 deletions

View File

@@ -15,14 +15,14 @@ declare(strict_types=1);
class PR_Core_Migration_0002_Legal_Cells {
/** @var string[] Valid legal status enum values. */
public const STATUSES = [
public const STATUSES = array(
'prescription',
'ruo',
'otc',
'restricted',
'banned',
'unclear',
];
);
/**
* Create the pr_legal_cells table.
@@ -61,7 +61,7 @@ class PR_Core_Migration_0002_Legal_Cells {
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$index_exists = $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(*) FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND INDEX_NAME = %s",
'SELECT COUNT(*) FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND INDEX_NAME = %s',
DB_NAME,
$table,
'uq_peptide_country_active'

View File

@@ -16,12 +16,12 @@ declare(strict_types=1);
class PR_Core_Migration_0003_Candidate_Queue {
/** @var string[] Valid queue status enum values. */
public const STATUSES = [
public const STATUSES = array(
'pending',
'approved',
'rejected',
'merged',
];
);
/**
* Create the pr_ai_candidate_queue table.

View File

@@ -34,7 +34,7 @@ class PR_Core_Migration_0004_Backfill_Peptide_Meta {
public const META_FORMULA = '_pr_molecular_formula';
/** @var string Meta key: molecular weight as float string (PR Core namespace). */
public const META_WEIGHT = '_pr_molecular_weight';
public const META_WEIGHT = '_pr_molecular_weight';
/** @var string Meta key: aliases JSON array (PR Core namespace). */
public const META_ALIASES = '_pr_aliases';
@@ -66,20 +66,27 @@ class PR_Core_Migration_0004_Backfill_Peptide_Meta {
return;
}
$counts = [ 'skipped' => 0, 'copied_psa' => 0, 'pubchem_ok' => 0, 'pubchem_skip' => 0 ];
$counts = array(
'skipped' => 0,
'copied_psa' => 0,
'pubchem_ok' => 0,
'pubchem_skip' => 0,
);
foreach ( $peptide_ids as $post_id ) {
$result = $this->backfill_post( $post_id );
$counts[ $result ] += 1;
}
error_log( sprintf(
'[PR Core Migration 0004] Complete. Skipped: %d, PSA-copied: %d, PubChem-ok: %d, PubChem-skip: %d',
$counts['skipped'],
$counts['copied_psa'],
$counts['pubchem_ok'],
$counts['pubchem_skip']
) );
error_log(
sprintf(
'[PR Core Migration 0004] Complete. Skipped: %d, PSA-copied: %d, PubChem-ok: %d, PubChem-skip: %d',
$counts['skipped'],
$counts['copied_psa'],
$counts['pubchem_ok'],
$counts['pubchem_skip']
)
);
}
/**
@@ -125,26 +132,30 @@ class PR_Core_Migration_0004_Backfill_Peptide_Meta {
}
if ( null === $data ) {
error_log( sprintf(
'[PR Core Migration 0004] Post ID %d (%s): PubChem returned no data — leaving meta empty.',
$post_id,
esc_html( $name )
) );
error_log(
sprintf(
'[PR Core Migration 0004] Post ID %d (%s): PubChem returned no data — leaving meta empty.',
$post_id,
esc_html( $name )
)
);
return 'pubchem_skip';
}
$formula = PR_Core_Schema_Sanitizers::sanitize_molecular_formula( $data['formula'] );
$weight = (float) $data['weight'];
$aliases_json = $this->synonyms_to_json( $data['synonyms'] ?? [] );
$aliases_json = $this->synonyms_to_json( $data['synonyms'] ?? array() );
$this->write_pr_meta( $post_id, $formula, $weight, $aliases_json );
error_log( sprintf(
'[PR Core Migration 0004] Post ID %d (%s): PubChem-sourced formula=%s weight=%s',
$post_id,
esc_html( $name ),
$formula,
(string) $weight
) );
error_log(
sprintf(
'[PR Core Migration 0004] Post ID %d (%s): PubChem-sourced formula=%s weight=%s',
$post_id,
esc_html( $name ),
$formula,
(string) $weight
)
);
return 'pubchem_ok';
}
@@ -223,7 +234,7 @@ class PR_Core_Migration_0004_Backfill_Peptide_Meta {
return '[]';
}
$clean = [];
$clean = array();
foreach ( explode( ',', $value ) as $part ) {
$alias = sanitize_text_field( trim( $part ) );
if ( '' !== $alias ) {
@@ -243,7 +254,7 @@ class PR_Core_Migration_0004_Backfill_Peptide_Meta {
* @return string JSON array of sanitized strings.
*/
private function synonyms_to_json( array $synonyms ): string {
$clean = [];
$clean = array();
foreach ( $synonyms as $syn ) {
$alias = sanitize_text_field( (string) $syn );
if ( '' !== $alias ) {
@@ -259,12 +270,14 @@ class PR_Core_Migration_0004_Backfill_Peptide_Meta {
* @return int[]
*/
private function get_all_peptide_ids(): array {
$posts = get_posts( [
'post_type' => PR_Core_Peptide_CPT::POST_TYPE,
'post_status' => 'publish',
'posts_per_page' => -1,
'fields' => 'ids',
] );
return array_map( 'intval', is_array( $posts ) ? $posts : [] );
$posts = get_posts(
array(
'post_type' => PR_Core_Peptide_CPT::POST_TYPE,
'post_status' => 'publish',
'posts_per_page' => -1,
'fields' => 'ids',
)
);
return array_map( 'intval', is_array( $posts ) ? $posts : array() );
}
}

View File

@@ -25,12 +25,12 @@ class PR_Core_Migration_Runner {
*
* @var string[]
*/
private const MIGRATIONS = [
private const MIGRATIONS = array(
'PR_Core_Migration_0001_Dosing_Rows',
'PR_Core_Migration_0002_Legal_Cells',
'PR_Core_Migration_0003_Candidate_Queue',
'PR_Core_Migration_0004_Backfill_Peptide_Meta',
];
);
/**
* Run all pending migrations up to PR_CORE_TARGET_SCHEMA_VERSION.
@@ -90,7 +90,7 @@ class PR_Core_Migration_Runner {
* @return string Absolute file path.
*/
private function class_to_file( string $class ): string {
$suffix = substr( $class, 8 ); // Strip 'PR_Core_'.
$suffix = substr( $class, 8 ); // Strip 'PR_Core_'.
$filename = 'class-pr-core-' . str_replace( '_', '-', strtolower( $suffix ) ) . '.php';
return PR_CORE_PLUGIN_DIR . 'includes/migrations/' . $filename;

View File

@@ -109,11 +109,11 @@ class PR_Core_Pubchem_Client {
return null;
}
return [
return array(
'formula' => $formula,
'weight' => $weight,
'cid' => $cid,
];
);
}
/**
@@ -130,14 +130,14 @@ class PR_Core_Pubchem_Client {
$body = $this->get_with_retry( $url );
if ( null === $body ) {
return [];
return array();
}
$data = json_decode( $body, true );
$synonyms = $data['InformationList']['Information'][0]['Synonym'] ?? [];
$synonyms = $data['InformationList']['Information'][0]['Synonym'] ?? array();
if ( ! is_array( $synonyms ) ) {
return [];
return array();
}
return array_slice( $synonyms, 0, self::MAX_SYNONYMS );
@@ -176,10 +176,13 @@ class PR_Core_Pubchem_Client {
*/
private function get_once( string $url ): ?string {
if ( function_exists( 'wp_remote_get' ) ) {
$response = wp_remote_get( $url, [
'timeout' => self::TIMEOUT,
'headers' => [ 'Accept' => 'application/json' ],
] );
$response = wp_remote_get(
$url,
array(
'timeout' => self::TIMEOUT,
'headers' => array( 'Accept' => 'application/json' ),
)
);
if ( is_wp_error( $response ) ) {
return null;
@@ -194,13 +197,15 @@ class PR_Core_Pubchem_Client {
}
// WP-CLI / plain PHP fallback.
$context = stream_context_create( [
'http' => [
'timeout' => self::TIMEOUT,
'header' => "Accept: application/json\r\n",
'method' => 'GET',
],
] );
$context = stream_context_create(
array(
'http' => array(
'timeout' => self::TIMEOUT,
'header' => "Accept: application/json\r\n",
'method' => 'GET',
),
)
);
$body = @file_get_contents( $url, false, $context );
return ( false === $body ) ? null : $body;