style: auto-fix PHPCS violations via phpcbf
This commit is contained in:
@@ -73,19 +73,19 @@ class PRV_Call_Drawer_Renderer {
|
||||
* @return void
|
||||
*/
|
||||
public function render_content( array $meta, ?array $io ): void {
|
||||
$id = (int) $meta['id'];
|
||||
$captured = (string) $meta['captured_at'];
|
||||
$peptide = (string) $meta['peptide_slug'];
|
||||
$model = (string) $meta['model'];
|
||||
$intent = (string) $meta['intent_label'];
|
||||
$id = (int) $meta['id'];
|
||||
$captured = (string) $meta['captured_at'];
|
||||
$peptide = (string) $meta['peptide_slug'];
|
||||
$model = (string) $meta['model'];
|
||||
$intent = (string) $meta['intent_label'];
|
||||
$http_status = (int) ( $meta['http_status'] ?? 200 );
|
||||
$is_error = $http_status >= 400;
|
||||
$cited = isset( $meta['cited'] ) ? $meta['cited'] : null;
|
||||
$tok_in = isset( $meta['tokens_in'] ) ? (int) $meta['tokens_in'] : null;
|
||||
$tok_out = isset( $meta['tokens_out'] ) ? (int) $meta['tokens_out'] : null;
|
||||
$latency_ms = isset( $meta['latency_ms'] ) ? (int) $meta['latency_ms'] : null;
|
||||
$cost_usd = (float) ( $meta['cost_usd'] ?? 0.0 );
|
||||
$run_id = (string) ( $meta['run_id'] ?? '' );
|
||||
$is_error = $http_status >= 400;
|
||||
$cited = isset( $meta['cited'] ) ? $meta['cited'] : null;
|
||||
$tok_in = isset( $meta['tokens_in'] ) ? (int) $meta['tokens_in'] : null;
|
||||
$tok_out = isset( $meta['tokens_out'] ) ? (int) $meta['tokens_out'] : null;
|
||||
$latency_ms = isset( $meta['latency_ms'] ) ? (int) $meta['latency_ms'] : null;
|
||||
$cost_usd = (float) ( $meta['cost_usd'] ?? 0.0 );
|
||||
$run_id = (string) ( $meta['run_id'] ?? '' );
|
||||
$config_ver = isset( $meta['config_version'] ) ? (int) $meta['config_version'] : null;
|
||||
$io_captured = isset( $meta['io_captured'] ) ? (int) $meta['io_captured'] : 0;
|
||||
|
||||
@@ -93,7 +93,7 @@ class PRV_Call_Drawer_Renderer {
|
||||
// io_captured = 1 AND io row present → Normal.
|
||||
// io_captured = 1 AND io row absent → Pruned (aged out by retention cron).
|
||||
// io_captured = 0 → Legacy / not captured (pre-feature row).
|
||||
$has_io = ( null !== $io );
|
||||
$has_io = ( null !== $io );
|
||||
$vis_row_null = empty( $meta['visibility_row'] );
|
||||
if ( ! $is_error ) {
|
||||
$is_legacy = ( 0 === $io_captured );
|
||||
|
||||
@@ -133,10 +133,10 @@ class PRV_Call_Log_Table_Renderer {
|
||||
|
||||
// Status filter.
|
||||
$status_opts = array(
|
||||
'' => __( 'All statuses', 'pr-vision' ),
|
||||
'cited' => __( 'Cited', 'pr-vision' ),
|
||||
'' => __( 'All statuses', 'pr-vision' ),
|
||||
'cited' => __( 'Cited', 'pr-vision' ),
|
||||
'not_cited' => __( 'Not cited', 'pr-vision' ),
|
||||
'error' => __( 'Error', 'pr-vision' ),
|
||||
'error' => __( 'Error', 'pr-vision' ),
|
||||
);
|
||||
echo '<label for="prv-f-status" class="prv-sr-only">' . esc_html__( 'Status', 'pr-vision' ) . '</label>';
|
||||
echo '<select id="prv-f-status" name="prv_filter_status" class="prv-filter-select">';
|
||||
@@ -180,12 +180,12 @@ class PRV_Call_Log_Table_Renderer {
|
||||
}
|
||||
|
||||
foreach ( $rows as $row ) {
|
||||
$id = (int) $row['id'];
|
||||
$is_error = ( (int) $row['http_status'] >= 400 );
|
||||
$cited_null = ( null === $row['cited'] );
|
||||
$is_cited = ! $cited_null && (bool) $row['cited'];
|
||||
$latency_ms = isset( $row['latency_ms'] ) ? (int) $row['latency_ms'] : null;
|
||||
$lat_warn = ( null !== $latency_ms && $latency_ms > 8000 ) ? ' style="color:#FFB36E"' : '';
|
||||
$id = (int) $row['id'];
|
||||
$is_error = ( (int) $row['http_status'] >= 400 );
|
||||
$cited_null = ( null === $row['cited'] );
|
||||
$is_cited = ! $cited_null && (bool) $row['cited'];
|
||||
$latency_ms = isset( $row['latency_ms'] ) ? (int) $row['latency_ms'] : null;
|
||||
$lat_warn = ( null !== $latency_ms && $latency_ms > 8000 ) ? ' style="color:#FFB36E"' : '';
|
||||
|
||||
$status_chip = $is_error ? '<span class="prv-chip prv-chip--error">✕ Error</span>' : '<span class="prv-chip prv-chip--ok">OK</span>';
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ class PRV_Config_Version {
|
||||
* @return int The new version number.
|
||||
*/
|
||||
private static function create_version_record(): int {
|
||||
$versions = get_option( self::VERSIONS_KEY, array() );
|
||||
$versions = get_option( self::VERSIONS_KEY, array() );
|
||||
if ( ! is_array( $versions ) ) {
|
||||
$versions = array();
|
||||
}
|
||||
|
||||
@@ -124,16 +124,16 @@ class PRV_Config {
|
||||
$per_probe = 0.005;
|
||||
$per_run = round( $probe_count * $per_probe, 4 );
|
||||
|
||||
$cadence = self::get_cadence();
|
||||
$runs_per_month = 'weekly' === $cadence ? 4 : ( 'daily' === $cadence ? 30 : 8 );
|
||||
$per_month = round( $per_run * $runs_per_month, 4 );
|
||||
$cap = self::get_monthly_budget_usd();
|
||||
$cadence = self::get_cadence();
|
||||
$runs_per_month = 'weekly' === $cadence ? 4 : ( 'daily' === $cadence ? 30 : 8 );
|
||||
$per_month = round( $per_run * $runs_per_month, 4 );
|
||||
$cap = self::get_monthly_budget_usd();
|
||||
|
||||
return array(
|
||||
'per_run_usd' => $per_run,
|
||||
'per_run_usd' => $per_run,
|
||||
'per_month_usd' => $per_month,
|
||||
'probe_count' => $probe_count,
|
||||
'over_cap' => $per_month > $cap,
|
||||
'probe_count' => $probe_count,
|
||||
'over_cap' => $per_month > $cap,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -99,12 +99,12 @@ class PRV_Cost_Rollup_Query {
|
||||
|
||||
$result = array();
|
||||
foreach ( (array) $rows as $row ) {
|
||||
$calls = (int) $row['calls'];
|
||||
$mtd_cost = (float) $row['mtd_cost'];
|
||||
$result[] = array(
|
||||
'model' => (string) $row['model'],
|
||||
'calls' => $calls,
|
||||
'mtd_cost' => $mtd_cost,
|
||||
$calls = (int) $row['calls'];
|
||||
$mtd_cost = (float) $row['mtd_cost'];
|
||||
$result[] = array(
|
||||
'model' => (string) $row['model'],
|
||||
'calls' => $calls,
|
||||
'mtd_cost' => $mtd_cost,
|
||||
'cost_per_call' => $calls > 0 ? $mtd_cost / $calls : 0.0,
|
||||
);
|
||||
}
|
||||
@@ -193,8 +193,8 @@ class PRV_Cost_Rollup_Query {
|
||||
* @return float Projected full-month cost.
|
||||
*/
|
||||
public function project_month_end( float $mtd_cost ): float {
|
||||
$days_in_month = (int) gmdate( 't' );
|
||||
$day_of_month = (int) gmdate( 'j' );
|
||||
$days_in_month = (int) gmdate( 't' );
|
||||
$day_of_month = (int) gmdate( 'j' );
|
||||
|
||||
if ( $day_of_month < 1 ) {
|
||||
return $mtd_cost;
|
||||
|
||||
@@ -75,14 +75,14 @@ class PRV_Costs_Page {
|
||||
|
||||
// Drill-down parameters.
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$level = isset( $_GET['prv_level'] ) ? sanitize_text_field( wp_unslash( $_GET['prv_level'] ) ) : 'run';
|
||||
$level = isset( $_GET['prv_level'] ) ? sanitize_text_field( wp_unslash( $_GET['prv_level'] ) ) : 'run';
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$offset = isset( $_GET['prv_offset'] ) ? absint( wp_unslash( $_GET['prv_offset'] ) ) : 0;
|
||||
$drill = $query->get_drill_down( $level, $offset );
|
||||
|
||||
$cap = PRV_Config::get_monthly_budget_usd();
|
||||
$mtd_cost = $summary['total_cost'];
|
||||
$projected = $query->project_month_end( $mtd_cost );
|
||||
$cap = PRV_Config::get_monthly_budget_usd();
|
||||
$mtd_cost = $summary['total_cost'];
|
||||
$projected = $query->project_month_end( $mtd_cost );
|
||||
|
||||
$renderer = new PRV_Costs_Renderer();
|
||||
$renderer->render(
|
||||
|
||||
@@ -44,9 +44,9 @@ class PRV_Costs_Renderer {
|
||||
$level = (string) $data['level'];
|
||||
$offset = (int) $data['offset'];
|
||||
|
||||
$meter_pct = $cap > 0 ? min( 100, round( ( $mtd_cost / $cap ) * 100 ) ) : 0;
|
||||
$meter_class = $meter_pct >= 90 ? ' prv-meter--capped' : '';
|
||||
$projected_warn = $projected > $cap;
|
||||
$meter_pct = $cap > 0 ? min( 100, round( ( $mtd_cost / $cap ) * 100 ) ) : 0;
|
||||
$meter_class = $meter_pct >= 90 ? ' prv-meter--capped' : '';
|
||||
$projected_warn = $projected > $cap;
|
||||
|
||||
echo '<div class="wrap prv-page-wrap">';
|
||||
$this->render_subnav( 'costs' );
|
||||
@@ -139,10 +139,10 @@ class PRV_Costs_Renderer {
|
||||
);
|
||||
echo '<nav class="prv-subnav" aria-label="' . esc_attr__( 'PR Vision navigation', 'pr-vision' ) . '">';
|
||||
foreach ( $tabs as $key => $tab ) {
|
||||
$is_active = ( $key === $active );
|
||||
$is_active = ( $key === $active );
|
||||
$aria_current = $is_active ? ' aria-current="page"' : '';
|
||||
$tab_class = 'prv-subnav-tab' . ( $is_active ? ' prv-subnav-tab--active' : '' );
|
||||
$url = admin_url( 'admin.php?page=' . rawurlencode( $tab['slug'] ) );
|
||||
$tab_class = 'prv-subnav-tab' . ( $is_active ? ' prv-subnav-tab--active' : '' );
|
||||
$url = admin_url( 'admin.php?page=' . rawurlencode( $tab['slug'] ) );
|
||||
echo '<a href="' . esc_url( $url ) . '" class="' . esc_attr( $tab_class ) . '"' . $aria_current . '>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- aria-current is safe static string
|
||||
echo esc_html( $tab['label'] );
|
||||
echo '</a>';
|
||||
|
||||
@@ -138,9 +138,9 @@ class PRV_Model_Manager_Table {
|
||||
* @return string HTML badge (pre-escaped).
|
||||
*/
|
||||
private function render_health_badge( array $m ): string {
|
||||
$status = (string) ( $m['health_status'] ?? 'unknown' );
|
||||
$probed = (int) ( $m['health_probed'] ?? 0 );
|
||||
$errors = (int) ( $m['health_errors'] ?? 0 );
|
||||
$status = (string) ( $m['health_status'] ?? 'unknown' );
|
||||
$probed = (int) ( $m['health_probed'] ?? 0 );
|
||||
$errors = (int) ( $m['health_errors'] ?? 0 );
|
||||
|
||||
switch ( $status ) {
|
||||
case 'healthy':
|
||||
|
||||
@@ -212,7 +212,7 @@ class PRV_Model_Registry {
|
||||
if ( ! isset( $outcomes[ $slug ] ) ) {
|
||||
continue;
|
||||
}
|
||||
$o = $outcomes[ $slug ];
|
||||
$o = $outcomes[ $slug ];
|
||||
$m['health_probed'] = (int) $o['probed'];
|
||||
$m['health_errors'] = (int) $o['errors'];
|
||||
$m['health_run_id'] = $run_id;
|
||||
|
||||
@@ -157,11 +157,11 @@ class PRV_Probe_Run_Executor {
|
||||
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine, Universal.WhiteSpace.CommaSpacing.TooMuchSpaceAfter
|
||||
$cid = $this->capture->write_meta(
|
||||
array(
|
||||
'visibility_row' => null, 'run_id' => $run_id,
|
||||
'peptide_slug' => $peptide['slug'], 'model' => $model,
|
||||
'intent_label' => $intent_tpl, 'tokens_in' => null,
|
||||
'tokens_out' => null, 'cost_usd' => 0.0,
|
||||
'latency_ms' => $latency_ms, 'cited' => null,
|
||||
'visibility_row' => null, 'run_id' => $run_id,
|
||||
'peptide_slug' => $peptide['slug'], 'model' => $model,
|
||||
'intent_label' => $intent_tpl, 'tokens_in' => null,
|
||||
'tokens_out' => null, 'cost_usd' => 0.0,
|
||||
'latency_ms' => $latency_ms, 'cited' => null,
|
||||
'http_status' => $http_status, 'config_version' => $config_ver,
|
||||
)
|
||||
); // phpcs:enable
|
||||
@@ -184,11 +184,11 @@ class PRV_Probe_Run_Executor {
|
||||
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine, Universal.WhiteSpace.CommaSpacing.TooMuchSpaceAfter
|
||||
$cid = $this->capture->write_meta(
|
||||
array(
|
||||
'visibility_row' => $row_id > 0 ? $row_id : null, 'run_id' => $run_id,
|
||||
'peptide_slug' => $peptide['slug'], 'model' => $model,
|
||||
'intent_label' => $intent_tpl, 'tokens_in' => $result->get_tokens_in(),
|
||||
'tokens_out' => $result->get_tokens_out(), 'cost_usd' => $result->get_cost_usd(),
|
||||
'latency_ms' => $latency_ms, 'cited' => $result->is_cited() ? 1 : 0,
|
||||
'visibility_row' => $row_id > 0 ? $row_id : null, 'run_id' => $run_id,
|
||||
'peptide_slug' => $peptide['slug'], 'model' => $model,
|
||||
'intent_label' => $intent_tpl, 'tokens_in' => $result->get_tokens_in(),
|
||||
'tokens_out' => $result->get_tokens_out(), 'cost_usd' => $result->get_cost_usd(),
|
||||
'latency_ms' => $latency_ms, 'cited' => $result->is_cited() ? 1 : 0,
|
||||
'http_status' => $http_status, 'config_version' => $config_ver,
|
||||
)
|
||||
); // phpcs:enable
|
||||
|
||||
@@ -72,7 +72,7 @@ class PRV_Settings_Controller {
|
||||
$old_cadence = PRV_Config::get_cadence();
|
||||
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing -- nonce verified above.
|
||||
$budget = isset( $_POST['prv_monthly_budget_usd'] )
|
||||
$budget = isset( $_POST['prv_monthly_budget_usd'] )
|
||||
? max( 0.01, (float) sanitize_text_field( wp_unslash( (string) $_POST['prv_monthly_budget_usd'] ) ) )
|
||||
: PRV_DEFAULT_MONTHLY_BUDGET_USD;
|
||||
update_option( 'prv_monthly_budget_usd', $budget );
|
||||
@@ -85,7 +85,7 @@ class PRV_Settings_Controller {
|
||||
$cadence_raw = isset( $_POST['prv_cadence'] )
|
||||
? sanitize_text_field( wp_unslash( (string) $_POST['prv_cadence'] ) )
|
||||
: 'weekly';
|
||||
$cadence = in_array( $cadence_raw, array( 'weekly', 'daily', 'twicedaily' ), true ) ? $cadence_raw : 'weekly';
|
||||
$cadence = in_array( $cadence_raw, array( 'weekly', 'daily', 'twicedaily' ), true ) ? $cadence_raw : 'weekly';
|
||||
update_option( PRV_Config::CADENCE_KEY, $cadence );
|
||||
|
||||
if ( ! empty( $_POST['prv_peptides_json'] ) ) {
|
||||
@@ -153,8 +153,8 @@ class PRV_Settings_Controller {
|
||||
$result_arg = 'prv_key_unchanged';
|
||||
|
||||
if ( '' !== $raw_key ) {
|
||||
$stored = PRV_Key_Store::store_key( $raw_key );
|
||||
$result_arg = $stored ? 'prv_key_set' : 'prv_key_error';
|
||||
$stored = PRV_Key_Store::store_key( $raw_key );
|
||||
$result_arg = $stored ? 'prv_key_set' : 'prv_key_error';
|
||||
// Explicitly unset to prevent the plaintext lingering in memory.
|
||||
unset( $raw_key );
|
||||
}
|
||||
@@ -162,8 +162,8 @@ class PRV_Settings_Controller {
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
array(
|
||||
'page' => self::MENU_SLUG,
|
||||
$result_arg => 1,
|
||||
'page' => self::MENU_SLUG,
|
||||
$result_arg => 1,
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user