style: auto-fix PHPCS violations via phpcbf
This commit is contained in:
@@ -47,15 +47,15 @@ class PR_Core_Candidate_Queue_Repository {
|
||||
global $wpdb;
|
||||
$table = $wpdb->prefix . 'pr_ai_candidate_queue';
|
||||
|
||||
$where = [ 'queue_status = %s' ];
|
||||
$params = [ sanitize_text_field( $status ) ];
|
||||
$where = array( 'queue_status = %s' );
|
||||
$params = array( sanitize_text_field( $status ) );
|
||||
|
||||
if ( $peptide_id > 0 ) {
|
||||
$where[] = 'peptide_id = %d';
|
||||
$params[] = $peptide_id;
|
||||
}
|
||||
|
||||
$params[] = $limit;
|
||||
$params[] = $limit;
|
||||
$where_sql = implode( ' AND ', $where );
|
||||
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
|
||||
@@ -65,7 +65,7 @@ class PR_Core_Candidate_Queue_Repository {
|
||||
...$params
|
||||
),
|
||||
ARRAY_A
|
||||
) ?: [];
|
||||
) ?: array();
|
||||
|
||||
return array_map(
|
||||
static fn( array $row ) => new PR_Core_Candidate_DTO( $row ),
|
||||
@@ -85,7 +85,7 @@ class PR_Core_Candidate_Queue_Repository {
|
||||
global $wpdb;
|
||||
$table = $wpdb->prefix . 'pr_ai_candidate_queue';
|
||||
|
||||
$row = [
|
||||
$row = array(
|
||||
'peptide_id' => absint( $data['peptide_id'] ?? 0 ),
|
||||
'dose_min' => isset( $data['dose_min'] ) ? (float) $data['dose_min'] : null,
|
||||
'dose_max' => isset( $data['dose_max'] ) ? (float) $data['dose_max'] : null,
|
||||
@@ -106,7 +106,7 @@ class PR_Core_Candidate_Queue_Repository {
|
||||
'extraction_confidence' => (float) ( $data['extraction_confidence'] ?? 0 ),
|
||||
'queue_status' => 'pending',
|
||||
'extracted_at' => current_time( 'mysql' ),
|
||||
];
|
||||
);
|
||||
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
|
||||
$result = $wpdb->insert( $table, $row );
|
||||
@@ -134,30 +134,32 @@ class PR_Core_Candidate_Queue_Repository {
|
||||
|
||||
// Copy candidate data into a dosing row.
|
||||
$dosing_repo = new PR_Core_Dosing_Repository();
|
||||
$dosing_id = $dosing_repo->insert( [
|
||||
'peptide_id' => $candidate->peptide_id,
|
||||
'dose_min' => $candidate->dose_min,
|
||||
'dose_max' => $candidate->dose_max,
|
||||
'dose_unit' => $candidate->dose_unit,
|
||||
'route' => $candidate->route,
|
||||
'frequency' => $candidate->frequency,
|
||||
'duration_value' => $candidate->duration_value,
|
||||
'duration_unit' => $candidate->duration_unit,
|
||||
'population' => $candidate->population,
|
||||
'indication' => $candidate->indication,
|
||||
'evidence_strength' => $candidate->evidence_strength,
|
||||
'study_title' => $candidate->study_title,
|
||||
'study_year' => $candidate->study_year,
|
||||
'citation_pubmed_id' => $candidate->citation_pubmed_id,
|
||||
'citation_doi' => $candidate->citation_doi,
|
||||
'citation_url' => $candidate->citation_url,
|
||||
'notes' => $candidate->notes,
|
||||
'source' => 'ai-candidate-approved',
|
||||
'ai_candidate_id' => $candidate_id,
|
||||
'added_by' => $reviewer_id,
|
||||
'reviewed_by' => $reviewer_id,
|
||||
'reviewed_at' => current_time( 'mysql' ),
|
||||
] );
|
||||
$dosing_id = $dosing_repo->insert(
|
||||
array(
|
||||
'peptide_id' => $candidate->peptide_id,
|
||||
'dose_min' => $candidate->dose_min,
|
||||
'dose_max' => $candidate->dose_max,
|
||||
'dose_unit' => $candidate->dose_unit,
|
||||
'route' => $candidate->route,
|
||||
'frequency' => $candidate->frequency,
|
||||
'duration_value' => $candidate->duration_value,
|
||||
'duration_unit' => $candidate->duration_unit,
|
||||
'population' => $candidate->population,
|
||||
'indication' => $candidate->indication,
|
||||
'evidence_strength' => $candidate->evidence_strength,
|
||||
'study_title' => $candidate->study_title,
|
||||
'study_year' => $candidate->study_year,
|
||||
'citation_pubmed_id' => $candidate->citation_pubmed_id,
|
||||
'citation_doi' => $candidate->citation_doi,
|
||||
'citation_url' => $candidate->citation_url,
|
||||
'notes' => $candidate->notes,
|
||||
'source' => 'ai-candidate-approved',
|
||||
'ai_candidate_id' => $candidate_id,
|
||||
'added_by' => $reviewer_id,
|
||||
'reviewed_by' => $reviewer_id,
|
||||
'reviewed_at' => current_time( 'mysql' ),
|
||||
)
|
||||
);
|
||||
|
||||
if ( 0 === $dosing_id ) {
|
||||
return 0;
|
||||
@@ -224,15 +226,15 @@ class PR_Core_Candidate_Queue_Repository {
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
|
||||
$result = $wpdb->update(
|
||||
$table,
|
||||
[
|
||||
array(
|
||||
'queue_status' => sanitize_text_field( $status ),
|
||||
'reviewed_by' => $reviewer_id,
|
||||
'reviewed_at' => current_time( 'mysql' ),
|
||||
'reviewer_notes' => sanitize_textarea_field( $notes ),
|
||||
],
|
||||
[ 'id' => $id ],
|
||||
[ '%s', '%d', '%s', '%s' ],
|
||||
[ '%d' ]
|
||||
),
|
||||
array( 'id' => $id ),
|
||||
array( '%s', '%d', '%s', '%s' ),
|
||||
array( '%d' )
|
||||
);
|
||||
|
||||
return false !== $result;
|
||||
|
||||
@@ -39,12 +39,12 @@ class PR_Core_Dosing_Repository {
|
||||
* @param array<string, mixed> $filters Optional: route, population, evidence_strength.
|
||||
* @return PR_Core_Dosing_Row_DTO[]
|
||||
*/
|
||||
public function find_by_peptide( int $peptide_id, array $filters = [] ): array {
|
||||
public function find_by_peptide( int $peptide_id, array $filters = array() ): array {
|
||||
global $wpdb;
|
||||
$table = $wpdb->prefix . 'pr_dosing_rows';
|
||||
|
||||
$where = [ 'peptide_id = %d', 'superseded_by_id IS NULL' ];
|
||||
$params = [ $peptide_id ];
|
||||
$where = array( 'peptide_id = %d', 'superseded_by_id IS NULL' );
|
||||
$params = array( $peptide_id );
|
||||
|
||||
if ( ! empty( $filters['route'] ) ) {
|
||||
$where[] = 'route = %s';
|
||||
@@ -70,7 +70,7 @@ class PR_Core_Dosing_Repository {
|
||||
...$params
|
||||
),
|
||||
ARRAY_A
|
||||
) ?: [];
|
||||
) ?: array();
|
||||
|
||||
return array_map(
|
||||
static fn( array $row ) => new PR_Core_Dosing_Row_DTO( $row ),
|
||||
@@ -92,7 +92,7 @@ class PR_Core_Dosing_Repository {
|
||||
global $wpdb;
|
||||
$table = $wpdb->prefix . 'pr_dosing_rows';
|
||||
|
||||
$row = $this->sanitize_row( $data );
|
||||
$row = $this->sanitize_row( $data );
|
||||
$row['added_at'] = current_time( 'mysql' );
|
||||
$row['schema_version'] = 1;
|
||||
|
||||
@@ -137,10 +137,10 @@ class PR_Core_Dosing_Repository {
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
|
||||
$wpdb->update(
|
||||
$table,
|
||||
[ 'superseded_by_id' => $new_id ],
|
||||
[ 'id' => $old_id ],
|
||||
[ '%d' ],
|
||||
[ '%d' ]
|
||||
array( 'superseded_by_id' => $new_id ),
|
||||
array( 'id' => $old_id ),
|
||||
array( '%d' ),
|
||||
array( '%d' )
|
||||
);
|
||||
|
||||
return $new_id;
|
||||
@@ -172,7 +172,7 @@ class PR_Core_Dosing_Repository {
|
||||
* @return array<string, mixed> Sanitized row.
|
||||
*/
|
||||
private function sanitize_row( array $data ): array {
|
||||
return [
|
||||
return array(
|
||||
'peptide_id' => absint( $data['peptide_id'] ?? 0 ),
|
||||
'dose_min' => isset( $data['dose_min'] ) ? (float) $data['dose_min'] : null,
|
||||
'dose_max' => isset( $data['dose_max'] ) ? (float) $data['dose_max'] : null,
|
||||
@@ -195,6 +195,6 @@ class PR_Core_Dosing_Repository {
|
||||
'added_by' => absint( $data['added_by'] ?? get_current_user_id() ),
|
||||
'reviewed_by' => isset( $data['reviewed_by'] ) ? absint( $data['reviewed_by'] ) : null,
|
||||
'reviewed_at' => $data['reviewed_at'] ?? null,
|
||||
];
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class PR_Core_Legal_Repository {
|
||||
$peptide_id
|
||||
),
|
||||
ARRAY_A
|
||||
) ?: [];
|
||||
) ?: array();
|
||||
|
||||
return array_map(
|
||||
static fn( array $row ) => new PR_Core_Legal_Cell_DTO( $row ),
|
||||
@@ -101,7 +101,7 @@ class PR_Core_Legal_Repository {
|
||||
strtoupper( sanitize_text_field( $country_code ) )
|
||||
),
|
||||
ARRAY_A
|
||||
) ?: [];
|
||||
) ?: array();
|
||||
|
||||
return array_map(
|
||||
static fn( array $row ) => new PR_Core_Legal_Cell_DTO( $row ),
|
||||
@@ -161,10 +161,10 @@ class PR_Core_Legal_Repository {
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
|
||||
$wpdb->update(
|
||||
$table,
|
||||
[ 'superseded_by_id' => $new_id ],
|
||||
[ 'id' => $old_id ],
|
||||
[ '%d' ],
|
||||
[ '%d' ]
|
||||
array( 'superseded_by_id' => $new_id ),
|
||||
array( 'id' => $old_id ),
|
||||
array( '%d' ),
|
||||
array( '%d' )
|
||||
);
|
||||
|
||||
return $new_id;
|
||||
@@ -184,7 +184,7 @@ class PR_Core_Legal_Repository {
|
||||
$status = 'unclear';
|
||||
}
|
||||
|
||||
return [
|
||||
return array(
|
||||
'peptide_id' => absint( $data['peptide_id'] ?? 0 ),
|
||||
'country_code' => strtoupper( sanitize_text_field( $data['country_code'] ?? '' ) ),
|
||||
'status' => $status,
|
||||
@@ -195,6 +195,6 @@ class PR_Core_Legal_Repository {
|
||||
'last_verified_at' => sanitize_text_field( $data['last_verified_at'] ?? current_time( 'mysql' ) ),
|
||||
'schema_version' => 1,
|
||||
'reviewer_id' => absint( $data['reviewer_id'] ?? get_current_user_id() ),
|
||||
];
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,12 +36,14 @@ class PR_Core_Peptide_Repository {
|
||||
* @return PR_Core_Peptide_DTO|null
|
||||
*/
|
||||
public function find_by_slug( string $slug ): ?PR_Core_Peptide_DTO {
|
||||
$posts = get_posts( [
|
||||
'post_type' => PR_Core_Peptide_CPT::POST_TYPE,
|
||||
'name' => sanitize_title( $slug ),
|
||||
'posts_per_page' => 1,
|
||||
'post_status' => 'any',
|
||||
] );
|
||||
$posts = get_posts(
|
||||
array(
|
||||
'post_type' => PR_Core_Peptide_CPT::POST_TYPE,
|
||||
'name' => sanitize_title( $slug ),
|
||||
'posts_per_page' => 1,
|
||||
'post_status' => 'any',
|
||||
)
|
||||
);
|
||||
|
||||
return ! empty( $posts ) ? $this->post_to_dto( $posts[0] ) : null;
|
||||
}
|
||||
@@ -56,14 +58,16 @@ class PR_Core_Peptide_Repository {
|
||||
public function search( string $query, int $limit = 20 ): array {
|
||||
$query = sanitize_text_field( $query );
|
||||
|
||||
$posts = get_posts( [
|
||||
'post_type' => PR_Core_Peptide_CPT::POST_TYPE,
|
||||
's' => $query,
|
||||
'posts_per_page' => $limit,
|
||||
'post_status' => 'publish',
|
||||
] );
|
||||
$posts = get_posts(
|
||||
array(
|
||||
'post_type' => PR_Core_Peptide_CPT::POST_TYPE,
|
||||
's' => $query,
|
||||
'posts_per_page' => $limit,
|
||||
'post_status' => 'publish',
|
||||
)
|
||||
);
|
||||
|
||||
return array_map( [ $this, 'post_to_dto' ], $posts );
|
||||
return array_map( array( $this, 'post_to_dto' ), $posts );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,23 +77,25 @@ class PR_Core_Peptide_Repository {
|
||||
* evidence_strength, per_page, page.
|
||||
* @return PR_Core_Peptide_DTO[]
|
||||
*/
|
||||
public function find_all( array $filters = [] ): array {
|
||||
$args = [
|
||||
public function find_all( array $filters = array() ): array {
|
||||
$args = array(
|
||||
'post_type' => PR_Core_Peptide_CPT::POST_TYPE,
|
||||
'posts_per_page' => (int) ( $filters['per_page'] ?? 100 ),
|
||||
'paged' => (int) ( $filters['page'] ?? 1 ),
|
||||
'orderby' => 'title',
|
||||
'order' => 'ASC',
|
||||
];
|
||||
);
|
||||
|
||||
$args['post_status'] = $filters['status'] ?? 'publish';
|
||||
|
||||
if ( ! empty( $filters['category'] ) ) {
|
||||
$args['tax_query'] = [ [
|
||||
'taxonomy' => PR_Core_Peptide_CPT::TAX_CATEGORY,
|
||||
'field' => 'slug',
|
||||
'terms' => sanitize_text_field( $filters['category'] ),
|
||||
] ];
|
||||
$args['tax_query'] = array(
|
||||
array(
|
||||
'taxonomy' => PR_Core_Peptide_CPT::TAX_CATEGORY,
|
||||
'field' => 'slug',
|
||||
'terms' => sanitize_text_field( $filters['category'] ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// v0.2.0: `family` filter silently ignored — `pr_peptide_family` taxonomy
|
||||
@@ -98,15 +104,17 @@ class PR_Core_Peptide_Repository {
|
||||
// REST schema in a future minor bump.
|
||||
|
||||
if ( ! empty( $filters['evidence_strength'] ) ) {
|
||||
$args['meta_query'] = [ [
|
||||
'key' => 'evidence_strength',
|
||||
'value' => sanitize_text_field( $filters['evidence_strength'] ),
|
||||
] ];
|
||||
$args['meta_query'] = array(
|
||||
array(
|
||||
'key' => 'evidence_strength',
|
||||
'value' => sanitize_text_field( $filters['evidence_strength'] ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$posts = get_posts( $args );
|
||||
|
||||
return array_map( [ $this, 'post_to_dto' ], $posts );
|
||||
return array_map( array( $this, 'post_to_dto' ), $posts );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,34 +136,36 @@ class PR_Core_Peptide_Repository {
|
||||
*/
|
||||
private function post_to_dto( \WP_Post $post ): PR_Core_Peptide_DTO {
|
||||
$aliases_raw = get_post_meta( $post->ID, 'aliases', true );
|
||||
$aliases = json_decode( $aliases_raw ?: '[]', true ) ?: [];
|
||||
$aliases = json_decode( $aliases_raw ?: '[]', true ) ?: array();
|
||||
|
||||
$categories = wp_get_post_terms( $post->ID, PR_Core_Peptide_CPT::TAX_CATEGORY, [ 'fields' => 'names' ] );
|
||||
$categories = wp_get_post_terms( $post->ID, PR_Core_Peptide_CPT::TAX_CATEGORY, array( 'fields' => 'names' ) );
|
||||
// v0.2.0: `pr_peptide_family` taxonomy removed. DTO `families` field
|
||||
// preserved as empty array to keep the REST response shape stable for
|
||||
// clients; will be dropped in a future minor bump with a release note.
|
||||
$families = [];
|
||||
$families = array();
|
||||
|
||||
return new PR_Core_Peptide_DTO( [
|
||||
'id' => $post->ID,
|
||||
'title' => $post->post_title,
|
||||
'slug' => $post->post_name,
|
||||
'content' => $post->post_content,
|
||||
'excerpt' => $post->post_excerpt,
|
||||
'status' => $post->post_status,
|
||||
'display_name' => get_post_meta( $post->ID, 'display_name', true ) ?: '',
|
||||
'aliases' => $aliases,
|
||||
'molecular_formula' => get_post_meta( $post->ID, 'molecular_formula', true ) ?: '',
|
||||
'molecular_weight' => (float) get_post_meta( $post->ID, 'molecular_weight', true ),
|
||||
'cas_number' => get_post_meta( $post->ID, 'cas_number', true ) ?: '',
|
||||
'drugbank_id' => get_post_meta( $post->ID, 'drugbank_id', true ) ?: '',
|
||||
'chembl_id' => get_post_meta( $post->ID, 'chembl_id', true ) ?: '',
|
||||
'evidence_strength' => get_post_meta( $post->ID, 'evidence_strength', true ) ?: 'preclinical',
|
||||
'editorial_review_status' => get_post_meta( $post->ID, 'editorial_review_status', true ) ?: 'draft',
|
||||
'last_editorial_review_at' => get_post_meta( $post->ID, 'last_editorial_review_at', true ) ?: '',
|
||||
'medical_editor_id' => (int) get_post_meta( $post->ID, 'medical_editor_id', true ),
|
||||
'categories' => is_array( $categories ) ? $categories : [],
|
||||
'families' => $families,
|
||||
] );
|
||||
return new PR_Core_Peptide_DTO(
|
||||
array(
|
||||
'id' => $post->ID,
|
||||
'title' => $post->post_title,
|
||||
'slug' => $post->post_name,
|
||||
'content' => $post->post_content,
|
||||
'excerpt' => $post->post_excerpt,
|
||||
'status' => $post->post_status,
|
||||
'display_name' => get_post_meta( $post->ID, 'display_name', true ) ?: '',
|
||||
'aliases' => $aliases,
|
||||
'molecular_formula' => get_post_meta( $post->ID, 'molecular_formula', true ) ?: '',
|
||||
'molecular_weight' => (float) get_post_meta( $post->ID, 'molecular_weight', true ),
|
||||
'cas_number' => get_post_meta( $post->ID, 'cas_number', true ) ?: '',
|
||||
'drugbank_id' => get_post_meta( $post->ID, 'drugbank_id', true ) ?: '',
|
||||
'chembl_id' => get_post_meta( $post->ID, 'chembl_id', true ) ?: '',
|
||||
'evidence_strength' => get_post_meta( $post->ID, 'evidence_strength', true ) ?: 'preclinical',
|
||||
'editorial_review_status' => get_post_meta( $post->ID, 'editorial_review_status', true ) ?: 'draft',
|
||||
'last_editorial_review_at' => get_post_meta( $post->ID, 'last_editorial_review_at', true ) ?: '',
|
||||
'medical_editor_id' => (int) get_post_meta( $post->ID, 'medical_editor_id', true ),
|
||||
'categories' => is_array( $categories ) ? $categories : array(),
|
||||
'families' => $families,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user