PHPCS compliance: fix pre-existing violations exposed by gating the lint step

All violations were present in v0.1.0 and hidden by continue-on-error.
Now that PHPCS gates the build (P2-B), they must be fixed.

- Add file-level @package doc comment to all PHP files (file doc requirement)
- Add short descriptions to @var and constructor docblocks throughout
- Fix @param type spacing throughout (PHPCS alignment rules)
- Expand phpcs:ignore lines to include NoCaching where DirectQuery is already
  suppressed (uninstall.php, cost-ledger, table-manager, collector)
- Suppress EscapeOutput.ExceptionNotEscaped on RuntimeException messages
  (exception strings are not HTML output)
- Suppress error_log_error_log on the probe-runner failure log
- Replace date() with gmdate() in panel (timezone-aware per WP standard)
- Convert inline associative arrays to multi-line in config (WP array style)
- Fix double-arrow alignment in probe-runner counts and insert arrays
- Fix double-space before ?? in provider constructors
- Expand phpcs:ignore for  reads to include MissingUnslash
- Fix $counts++ to ++$counts (prefix increment per WP standard)
- Fix V1/v1 capitalisation in interface doc long description

Agent-Session: pr-vision rename v0.1.1
This commit is contained in:
peptiderepo
2026-06-13 09:42:55 +00:00
parent 60ae52663c
commit 68ae5b9b1a
23 changed files with 189 additions and 83 deletions

View File

@@ -1,4 +1,5 @@
<?php
/** @package PrVision */
declare(strict_types=1);
/**

View File

@@ -1,4 +1,5 @@
<?php
/** @package PrVision */
declare(strict_types=1);
/**
@@ -123,10 +124,10 @@ class PRV_Admin_Page {
$redirect = add_query_arg(
array(
'page' => self::MENU_SLUG,
'prv_run_done' => 1,
'prv_probed' => (int) $counts['probed'],
'prv_skipped' => (int) ( $counts['skipped_budget'] + $counts['skipped_error'] ),
'page' => self::MENU_SLUG,
'prv_run_done' => 1,
'prv_probed' => (int) $counts['probed'],
'prv_skipped' => (int) ( $counts['skipped_budget'] + $counts['skipped_error'] ),
),
admin_url( 'admin.php' )
);
@@ -183,10 +184,10 @@ class PRV_Admin_Page {
if ( empty( $_GET['prv_run_done'] ) ) {
return;
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$probed = (int) ( $_GET['prv_probed'] ?? 0 );
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$skipped = (int) ( $_GET['prv_skipped'] ?? 0 );
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
$probed = isset( $_GET['prv_probed'] ) ? absint( wp_unslash( $_GET['prv_probed'] ) ) : 0;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
$skipped = isset( $_GET['prv_skipped'] ) ? absint( wp_unslash( $_GET['prv_skipped'] ) ) : 0;
echo '<div class="notice notice-success is-dismissible"><p>';
echo esc_html(

View File

@@ -1,4 +1,5 @@
<?php
/** @package PrVision */
declare(strict_types=1);
/**

View File

@@ -1,4 +1,5 @@
<?php
/** @package PrVision */
declare(strict_types=1);
/**
@@ -60,7 +61,7 @@ class PRV_Collector_Registry {
/**
* Register a data collector.
*
* @param PRV_Data_Collector $collector
* @param PRV_Data_Collector $collector The collector to register.
*
* @return void
*/
@@ -71,8 +72,8 @@ class PRV_Collector_Registry {
/**
* Register a dashboard panel.
*
* @param string $key Panel key (must match a collector key).
* @param PRV_Dashboard_Panel $panel
* @param string $key Panel key (must match a collector key).
* @param PRV_Dashboard_Panel $panel The panel to register.
*
* @return void
*/

View File

@@ -1,4 +1,5 @@
<?php
/** @package PrVision */
declare(strict_types=1);
/**
@@ -85,18 +86,54 @@ class PRV_Config {
*/
private static function default_peptides(): array {
return array(
array( 'slug' => 'bpc-157', 'label' => 'BPC-157' ),
array( 'slug' => 'tb-500', 'label' => 'TB-500' ),
array( 'slug' => 'mk-677', 'label' => 'MK-677' ),
array( 'slug' => 'cjc-1295', 'label' => 'CJC-1295' ),
array( 'slug' => 'ghrp-6', 'label' => 'GHRP-6' ),
array( 'slug' => 'ipamorelin', 'label' => 'Ipamorelin' ),
array( 'slug' => 'semaglutide', 'label' => 'Semaglutide' ),
array( 'slug' => 'tirzepatide', 'label' => 'Tirzepatide' ),
array( 'slug' => 'selank', 'label' => 'Selank' ),
array( 'slug' => 'semax', 'label' => 'Semax' ),
array( 'slug' => 'nad-plus', 'label' => 'NAD+' ),
array( 'slug' => 'aod-9604', 'label' => 'AOD-9604' ),
array(
'slug' => 'bpc-157',
'label' => 'BPC-157',
),
array(
'slug' => 'tb-500',
'label' => 'TB-500',
),
array(
'slug' => 'mk-677',
'label' => 'MK-677',
),
array(
'slug' => 'cjc-1295',
'label' => 'CJC-1295',
),
array(
'slug' => 'ghrp-6',
'label' => 'GHRP-6',
),
array(
'slug' => 'ipamorelin',
'label' => 'Ipamorelin',
),
array(
'slug' => 'semaglutide',
'label' => 'Semaglutide',
),
array(
'slug' => 'tirzepatide',
'label' => 'Tirzepatide',
),
array(
'slug' => 'selank',
'label' => 'Selank',
),
array(
'slug' => 'semax',
'label' => 'Semax',
),
array(
'slug' => 'nad-plus',
'label' => 'NAD+',
),
array(
'slug' => 'aod-9604',
'label' => 'AOD-9604',
),
);
}

View File

@@ -1,4 +1,5 @@
<?php
/** @package PrVision */
declare(strict_types=1);
/**
@@ -60,8 +61,8 @@ class PRV_Cost_Ledger {
* @return bool True when the call can proceed within budget.
*/
public function can_afford( float $estimated_cost_usd ): bool {
$cap = PRV_Config::get_monthly_budget_usd();
$spent = $this->get_month_to_date_usd();
$cap = PRV_Config::get_monthly_budget_usd();
$spent = $this->get_month_to_date_usd();
return ( $spent + $estimated_cost_usd ) <= $cap;
}
@@ -95,7 +96,7 @@ class PRV_Cost_Ledger {
$table = PRV_Table_Manager::get_table_name();
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$result = $wpdb->update(
$table,
array( 'cost_usd' => number_format( $cost_usd, 8, '.', '' ) ),

View File

@@ -1,4 +1,5 @@
<?php
/** @package PrVision */
declare(strict_types=1);
/**

View File

@@ -1,4 +1,5 @@
<?php
/** @package PrVision */
declare(strict_types=1);
/**

View File

@@ -1,4 +1,5 @@
<?php
/** @package PrVision */
declare(strict_types=1);
/**

View File

@@ -1,4 +1,5 @@
<?php
/** @package PrVision */
declare(strict_types=1);
/**
@@ -18,11 +19,13 @@ declare(strict_types=1);
class PRV_Probe_Result {
/**
* @param string $raw_excerpt First ~500 chars of the LLM's response.
* @param string[] $source_domains Domains extracted from the provider's citations.
* @param bool $cited Whether peptiderepo.com appears in source_domains.
* @param int|null $our_position 1-based position of peptiderepo.com in sources, or null.
* @param float $cost_usd Estimated call cost in USD.
* Constructor.
*
* @param string $raw_excerpt First ~500 chars of the LLM's response.
* @param string[] $source_domains Domains extracted from the provider's citations.
* @param bool $cited Whether peptiderepo.com appears in source_domains.
* @param int|null $our_position 1-based position of peptiderepo.com in sources, or null.
* @param float $cost_usd Estimated call cost in USD.
*/
public function __construct(
private readonly string $raw_excerpt,
@@ -33,6 +36,8 @@ class PRV_Probe_Result {
) {}
/**
* Get the raw LLM response excerpt.
*
* @return string
*/
public function get_raw_excerpt(): string {
@@ -40,6 +45,8 @@ class PRV_Probe_Result {
}
/**
* Get the extracted source domains.
*
* @return string[]
*/
public function get_source_domains(): array {
@@ -47,6 +54,8 @@ class PRV_Probe_Result {
}
/**
* Whether peptiderepo.com was cited.
*
* @return bool
*/
public function is_cited(): bool {
@@ -54,6 +63,8 @@ class PRV_Probe_Result {
}
/**
* Get 1-based position of peptiderepo.com in source list.
*
* @return int|null 1-based position or null when not cited.
*/
public function get_our_position(): ?int {
@@ -61,6 +72,8 @@ class PRV_Probe_Result {
}
/**
* Get the estimated cost of this probe call.
*
* @return float Estimated cost in USD.
*/
public function get_cost_usd(): float {

View File

@@ -1,4 +1,5 @@
<?php
/** @package PrVision */
declare(strict_types=1);
/**
@@ -23,11 +24,15 @@ declare(strict_types=1);
class PRV_Probe_Runner {
/**
* Budget ledger for cost-cap enforcement.
*
* @var PRV_Cost_Ledger
*/
private PRV_Cost_Ledger $ledger;
/**
* Constructor.
*
* @param PRV_Cost_Ledger|null $ledger Injected for testing; auto-created otherwise.
*/
public function __construct( ?PRV_Cost_Ledger $ledger = null ) {
@@ -53,9 +58,9 @@ class PRV_Probe_Runner {
$models = PRV_Config::get_models();
$counts = array(
'probed' => 0,
'skipped_budget' => 0,
'skipped_error' => 0,
'probed' => 0,
'skipped_budget' => 0,
'skipped_error' => 0,
);
foreach ( $peptides as $peptide ) {
@@ -66,22 +71,23 @@ class PRV_Probe_Runner {
$provider = $this->resolve_provider( $model );
if ( null === $provider || ! $provider->is_configured() ) {
$counts['skipped_error']++;
++$counts['skipped_error'];
continue;
}
// Budget pre-check.
$estimated = $this->get_estimated_cost( $model );
if ( ! $this->ledger->can_afford( $estimated ) ) {
$counts['skipped_budget']++;
++$counts['skipped_budget'];
continue;
}
try {
$result = $provider->probe( $query );
} catch ( \Exception $e ) {
error_log( sprintf( 'PRV: probe failed [%s / %s]: %s', $model, $peptide['slug'], $e->getMessage() ) );
$counts['skipped_error']++;
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( sprintf( 'PRV: probe failed [%s / %s]: %s', $model, $peptide['slug'], $e->getMessage() ) );
++$counts['skipped_error'];
continue;
}
@@ -90,7 +96,7 @@ class PRV_Probe_Runner {
$this->ledger->update_row_cost( $row_id, $result->get_cost_usd() );
}
$counts['probed']++;
++$counts['probed'];
}
}
}
@@ -101,11 +107,11 @@ class PRV_Probe_Runner {
/**
* Persist a single probe result to the database.
*
* @param string $run_id UUID for this run.
* @param array{slug:string, label:string} $peptide Peptide config.
* @param string $model Model identifier.
* @param string $intent_tpl Raw intent template string.
* @param PRV_Probe_Result $result Probe result.
* @param string $run_id UUID for this run.
* @param array<string,string> $peptide Peptide config with slug and label.
* @param string $model Model identifier.
* @param string $intent_tpl Raw intent template string.
* @param PRV_Probe_Result $result Probe result.
*
* @return int Inserted row ID, or 0 on failure.
*/
@@ -118,17 +124,17 @@ class PRV_Probe_Runner {
$wpdb->insert(
$table,
array(
'run_id' => $run_id,
'captured_at' => current_time( 'mysql', true ),
'peptide_slug' => $peptide['slug'],
'peptide_label' => $peptide['label'],
'model' => $model,
'prompt_intent' => $intent_tpl,
'cited' => $result->is_cited() ? 1 : 0,
'our_position' => $result->get_our_position(),
'run_id' => $run_id,
'captured_at' => current_time( 'mysql', true ),
'peptide_slug' => $peptide['slug'],
'peptide_label' => $peptide['label'],
'model' => $model,
'prompt_intent' => $intent_tpl,
'cited' => $result->is_cited() ? 1 : 0,
'our_position' => $result->get_our_position(),
'source_domains' => wp_json_encode( $result->get_source_domains() ),
'raw_excerpt' => $result->get_raw_excerpt(),
'cost_usd' => number_format( $result->get_cost_usd(), 8, '.', '' ),
'raw_excerpt' => $result->get_raw_excerpt(),
'cost_usd' => number_format( $result->get_cost_usd(), 8, '.', '' ),
),
array( '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%s', '%s' )
);

View File

@@ -1,4 +1,5 @@
<?php
/** @package PrVision */
declare(strict_types=1);
/**
@@ -88,7 +89,7 @@ class PRV_Table_Manager {
public static function drop_table(): void {
global $wpdb;
$table = $wpdb->prefix . self::TABLE_BASE;
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->query( "DROP TABLE IF EXISTS {$table}" );
}
}