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:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
/** @package PrVision */
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
/** @package PrVision */
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
@@ -97,13 +98,14 @@ class PRV_Gateway_Client {
|
||||
$last_error = sprintf( 'HTTP %d', $status );
|
||||
if ( $attempt < PRV_MAX_RETRIES ) {
|
||||
$retry_after = wp_remote_retrieve_header( $response, 'retry-after' );
|
||||
$delay = $retry_after ? min( (int) $retry_after, 60 ) : PRV_RETRY_BASE_DELAY_SECONDS * (int) pow( 2, $attempt - 1 );
|
||||
$delay = $retry_after ? min( (int) $retry_after, 60 ) : PRV_RETRY_BASE_DELAY_SECONDS * (int) pow( 2, $attempt - 1 );
|
||||
sleep( $delay );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $status >= 400 ) {
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
|
||||
throw new \RuntimeException(
|
||||
sprintf( 'PR Vision gateway HTTP %d: %s', $status, substr( $raw_body, 0, 300 ) )
|
||||
);
|
||||
@@ -120,6 +122,7 @@ class PRV_Gateway_Client {
|
||||
remove_action( 'http_api_curl', $curl_filter, 99 );
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
|
||||
throw new \RuntimeException(
|
||||
sprintf( 'PR Vision: gateway failed after %d attempts. Last: %s', PRV_MAX_RETRIES, $last_error )
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
/** @package PrVision */
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
@@ -33,35 +34,44 @@ class PRV_OpenRouter_Provider implements PRV_Probe_Provider {
|
||||
const ESTIMATED_COST_PER_PROBE = 0.003;
|
||||
|
||||
/**
|
||||
* @var string OpenRouter model identifier (e.g. "openai/gpt-4o-search-preview").
|
||||
* OpenRouter model identifier (e.g. "openai/gpt-4o-search-preview").
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string $model;
|
||||
|
||||
/**
|
||||
* HTTP gateway client.
|
||||
*
|
||||
* @var PRV_Gateway_Client
|
||||
*/
|
||||
private PRV_Gateway_Client $gateway;
|
||||
|
||||
/**
|
||||
* Citation domain detector.
|
||||
*
|
||||
* @var PRV_Citation_Detector
|
||||
*/
|
||||
private PRV_Citation_Detector $detector;
|
||||
|
||||
/**
|
||||
* @param string $model OpenRouter model identifier.
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $model OpenRouter model identifier.
|
||||
* @param PRV_Gateway_Client|null $gateway Injected for testing.
|
||||
* @param PRV_Citation_Detector|null $detector Injected for testing.
|
||||
*/
|
||||
public function __construct( string $model, ?PRV_Gateway_Client $gateway = null, ?PRV_Citation_Detector $detector = null ) {
|
||||
$this->model = $model;
|
||||
$this->gateway = $gateway ?? new PRV_Gateway_Client();
|
||||
$this->gateway = $gateway ?? new PRV_Gateway_Client();
|
||||
$this->detector = $detector ?? new PRV_Citation_Detector();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @param string $query
|
||||
* @param string $query The search query to probe.
|
||||
*
|
||||
* @return PRV_Probe_Result
|
||||
* @throws \RuntimeException On permanent API failure.
|
||||
*/
|
||||
@@ -71,7 +81,10 @@ class PRV_OpenRouter_Provider implements PRV_Probe_Provider {
|
||||
$body = array(
|
||||
'model' => $this->model,
|
||||
'messages' => array(
|
||||
array( 'role' => 'user', 'content' => $query ),
|
||||
array(
|
||||
'role' => 'user',
|
||||
'content' => $query,
|
||||
),
|
||||
),
|
||||
'max_tokens' => 512,
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
/** @package PrVision */
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
@@ -36,21 +37,27 @@ class PRV_Perplexity_Provider implements PRV_Probe_Provider {
|
||||
const ESTIMATED_COST_PER_PROBE = 0.005;
|
||||
|
||||
/**
|
||||
* HTTP gateway client.
|
||||
*
|
||||
* @var PRV_Gateway_Client
|
||||
*/
|
||||
private PRV_Gateway_Client $gateway;
|
||||
|
||||
/**
|
||||
* Citation domain detector.
|
||||
*
|
||||
* @var PRV_Citation_Detector
|
||||
*/
|
||||
private PRV_Citation_Detector $detector;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param PRV_Gateway_Client|null $gateway Injected for testing; auto-created otherwise.
|
||||
* @param PRV_Citation_Detector|null $detector Injected for testing; auto-created otherwise.
|
||||
*/
|
||||
public function __construct( ?PRV_Gateway_Client $gateway = null, ?PRV_Citation_Detector $detector = null ) {
|
||||
$this->gateway = $gateway ?? new PRV_Gateway_Client();
|
||||
$this->gateway = $gateway ?? new PRV_Gateway_Client();
|
||||
$this->detector = $detector ?? new PRV_Citation_Detector();
|
||||
}
|
||||
|
||||
@@ -60,7 +67,7 @@ class PRV_Perplexity_Provider implements PRV_Probe_Provider {
|
||||
* Sends the query as a user message to perplexity/sonar via OpenRouter.
|
||||
* Parses the citations[] array from the OpenRouter response envelope.
|
||||
*
|
||||
* @param string $query
|
||||
* @param string $query The search query to probe.
|
||||
*
|
||||
* @return PRV_Probe_Result
|
||||
* @throws \RuntimeException On permanent API failure.
|
||||
@@ -69,9 +76,12 @@ class PRV_Perplexity_Provider implements PRV_Probe_Provider {
|
||||
$api_key = $this->resolve_api_key();
|
||||
|
||||
$body = array(
|
||||
'model' => self::MODEL,
|
||||
'messages' => array(
|
||||
array( 'role' => 'user', 'content' => $query ),
|
||||
'model' => self::MODEL,
|
||||
'messages' => array(
|
||||
array(
|
||||
'role' => 'user',
|
||||
'content' => $query,
|
||||
),
|
||||
),
|
||||
'max_tokens' => 512,
|
||||
);
|
||||
@@ -135,11 +145,12 @@ class PRV_Perplexity_Provider implements PRV_Probe_Provider {
|
||||
/**
|
||||
* Retrieve the OpenRouter API key from wp-config constants.
|
||||
*
|
||||
* @return string
|
||||
* @return string The API key.
|
||||
* @throws \RuntimeException When the constant is not defined or empty.
|
||||
*/
|
||||
private function resolve_api_key(): string {
|
||||
if ( ! defined( 'PRV_OPENROUTER_API_KEY' ) || '' === PRV_OPENROUTER_API_KEY ) {
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
|
||||
throw new \RuntimeException(
|
||||
__( 'PRV_OPENROUTER_API_KEY constant is not defined. Add it to wp-config.php.', 'pr-vision' )
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
/** @package PrVision */
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user