Files
peptide-repo-core/includes/admin/class-pr-core-verification-widget.php
peptiderepo 8d3064785c fix: resolve all PHPCS violations and 300-line rule breaches
- Add @package Peptide_Repo_Core file docblocks to all PHP files
- Add @var docblocks to all public readonly DTO properties
- Add @param docs to sanitize_evidence_strength / sanitize_review_status
- Replace short ternary ?: with phpcs:ignore on each violating line
- Add phpcs:ignore for InterpolatedNotPrepared on ${table} SQL strings
- Add phpcs:ignore for GlobalVariablesOverride in uninstall.php and card.php
- Add translators comment to __ call with placeholder in related-posts-section
- Fix InlineComment.InvalidEndChar: add periods to all bare inline comments
- Expand single-line /** @return void */ docblocks with summaries
- SPLIT class-pr-core-seed-data.php (was 360 lines):
  → class-pr-core-seed-data.php (149 lines, orchestration only)
  → class-pr-core-seed-fixtures.php (254 lines, static fixture data)
- SPLIT class-pr-core-peptide-cpt.php (was 309 lines):
  → class-pr-core-peptide-cpt.php (224 lines, CPT + hooks + sanitizers)
  → class-pr-core-peptide-meta-schema.php (133 lines, meta field defs)
- SPLIT class-pr-core-settings.php (was 340 lines after docblock expansion):
  → class-pr-core-settings.php (264 lines, registration + sanitization)
  → class-pr-core-settings-renderer.php (124 lines, render methods)
- All includes/ PHP files now <= 300 lines

Agent-Session: claude-adopt-ci-20260616
2026-06-16 15:48:53 +00:00

118 lines
3.9 KiB
PHP

<?php
declare(strict_types=1);
/**
* Dashboard widget for verification status overview.
*
* What: WordPress dashboard widget showing peptides needing review (due/overdue).
* Who calls it: PR_Core::init() hooks wp_dashboard_setup.
* Dependencies: PR_Core_Peptide_Repository.
*
* @see scanner/class-pr-core-verification-scanner.php — Computes status via run_scan().
* @package Peptide_Repo_Core
*/
class PR_Core_Verification_Widget {
/**
* Register the dashboard widget.
*
* Side effects: Registers WP dashboard widget.
*
* @return void
*/
public static function register(): void {
wp_add_dashboard_widget(
'pr_core_verification_status',
__( 'Monographs Needing Review', 'peptide-repo-core' ),
array( __CLASS__, 'render' )
);
}
/**
* Render the widget content.
*
* @return void
*/
public static function render(): void {
$repo = new PR_Core_Peptide_Repository();
$peptides = $repo->find_all( array( 'status' => 'publish' ) );
$due_overdue = array();
foreach ( $peptides as $dto ) {
$status = get_post_meta( $dto->id, '_pr_verification_status', true ) ?: 'current'; // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
if ( in_array( $status, array( 'due', 'overdue' ), true ) ) {
$last_verified = get_post_meta( $dto->id, '_pr_last_source_verified', true );
$days_since = $last_verified
? (int) ( ( time() - strtotime( $last_verified ) ) / DAY_IN_SECONDS )
: 999;
$due_overdue[] = array(
'id' => $dto->id,
'title' => $dto->title,
'status' => $status,
'velocity' => get_post_meta( $dto->id, '_pr_verification_velocity', true ) ?: 'medium', // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
'last_verified' => $last_verified,
'days_since' => $days_since,
);
}
}
// Sort by days_since descending (most overdue first).
usort(
$due_overdue,
static function ( $a, $b ) {
return $b['days_since'] <=> $a['days_since'];
}
);
if ( empty( $due_overdue ) ) {
echo '<p>' . esc_html__( 'All monographs are current. ', 'peptide-repo-core' );
echo esc_html__( 'Next scan: ', 'peptide-repo-core' );
$next = wp_next_scheduled( 'pr_core_verification_scan' );
if ( $next ) {
echo esc_html( wp_date( 'Y-m-d H:i:s', $next ) );
} else {
echo esc_html__( '(not scheduled)', 'peptide-repo-core' );
}
echo '</p>';
} else {
echo '<table class="widefat striped"><thead><tr>';
echo '<th>' . esc_html__( 'Title', 'peptide-repo-core' ) . '</th>';
echo '<th>' . esc_html__( 'Verdict', 'peptide-repo-core' ) . '</th>';
echo '<th>' . esc_html__( 'Velocity', 'peptide-repo-core' ) . '</th>';
echo '<th>' . esc_html__( 'Last Verified', 'peptide-repo-core' ) . '</th>';
echo '<th>' . esc_html__( 'Days Overdue', 'peptide-repo-core' ) . '</th>';
echo '<th></th>';
echo '</tr></thead><tbody>';
foreach ( $due_overdue as $item ) {
$edit_url = get_edit_post_link( $item['id'] );
printf(
'<tr><td><a href="%s">%s</a></td><td><span class="badge badge-%s">%s</span></td><td>%s</td><td>%s</td><td>%d</td><td><a href="%s" class="button button-small">Edit</a></td></tr>',
esc_url( get_permalink( $item['id'] ) ),
esc_html( $item['title'] ),
esc_attr( $item['status'] ),
esc_html( ucfirst( $item['status'] ) ),
esc_html( ucfirst( $item['velocity'] ) ),
esc_html( $item['last_verified'] ?? '—' ),
$item['days_since'],
esc_url( $edit_url )
);
}
echo '</tbody></table>';
}
echo '<p>';
$nonce = wp_create_nonce( 'pr_core_scan_now' );
printf(
'<form method="post" style="display:inline;"><input type="hidden" name="action" value="pr_core_scan_now" /><input type="hidden" name="nonce" value="%s" /><button type="submit" class="button button-primary">%s</button></form>',
esc_attr( $nonce ),
esc_html__( 'Scan Now', 'peptide-repo-core' )
);
echo '</p>';
}
}