diff --git a/includes/collector/class-prv-ai-visibility-collector.php b/includes/collector/class-prv-ai-visibility-collector.php index 26aab12..0b66464 100644 --- a/includes/collector/class-prv-ai-visibility-collector.php +++ b/includes/collector/class-prv-ai-visibility-collector.php @@ -117,7 +117,7 @@ class PRV_Ai_Visibility_Collector implements PRV_Data_Collector { $standings = array(); foreach ( (array) $standing_rows as $row ) { - $top_domains = $this->extract_top_domains( (string) ( $row['domains_json_list'] ?? '' ) ); + $top_domains = $this->extract_top_domains( (string) ( $row['domains_json_list'] ?? '' ) ); $standings[ (string) $row['peptide_slug'] ] = array( 'label' => (string) $row['peptide_label'], 'cited' => (bool) (int) $row['cited'], diff --git a/includes/core/class-prv-call-drawer-renderer.php b/includes/core/class-prv-call-drawer-renderer.php index 729c676..95bf72a 100644 --- a/includes/core/class-prv-call-drawer-renderer.php +++ b/includes/core/class-prv-call-drawer-renderer.php @@ -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 ); diff --git a/includes/core/class-prv-call-log-table-renderer.php b/includes/core/class-prv-call-log-table-renderer.php index b123c3d..d09edda 100644 --- a/includes/core/class-prv-call-log-table-renderer.php +++ b/includes/core/class-prv-call-log-table-renderer.php @@ -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 '' . esc_html__( 'Status', 'pr-vision' ) . ''; echo ''; @@ -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 ? '✕ Error' : 'OK'; diff --git a/includes/core/class-prv-config-version.php b/includes/core/class-prv-config-version.php index 2ccf178..4232fb7 100644 --- a/includes/core/class-prv-config-version.php +++ b/includes/core/class-prv-config-version.php @@ -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(); } diff --git a/includes/core/class-prv-config.php b/includes/core/class-prv-config.php index 699bfd1..b2ff631 100644 --- a/includes/core/class-prv-config.php +++ b/includes/core/class-prv-config.php @@ -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, ); } diff --git a/includes/core/class-prv-cost-rollup-query.php b/includes/core/class-prv-cost-rollup-query.php index ca2bc01..44ccf4d 100644 --- a/includes/core/class-prv-cost-rollup-query.php +++ b/includes/core/class-prv-cost-rollup-query.php @@ -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; diff --git a/includes/core/class-prv-costs-page.php b/includes/core/class-prv-costs-page.php index 08f7b3f..257467e 100644 --- a/includes/core/class-prv-costs-page.php +++ b/includes/core/class-prv-costs-page.php @@ -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( diff --git a/includes/core/class-prv-costs-renderer.php b/includes/core/class-prv-costs-renderer.php index 52a9d94..5d4db86 100644 --- a/includes/core/class-prv-costs-renderer.php +++ b/includes/core/class-prv-costs-renderer.php @@ -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 ''; $this->render_subnav( 'costs' ); @@ -139,10 +139,10 @@ class PRV_Costs_Renderer { ); echo ''; 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 ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- aria-current is safe static string echo esc_html( $tab['label'] ); echo ''; diff --git a/includes/core/class-prv-model-manager-table.php b/includes/core/class-prv-model-manager-table.php index 4318846..9cc13a4 100644 --- a/includes/core/class-prv-model-manager-table.php +++ b/includes/core/class-prv-model-manager-table.php @@ -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': diff --git a/includes/core/class-prv-model-registry.php b/includes/core/class-prv-model-registry.php index d178134..2e0016b 100644 --- a/includes/core/class-prv-model-registry.php +++ b/includes/core/class-prv-model-registry.php @@ -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; diff --git a/includes/core/class-prv-probe-run-executor.php b/includes/core/class-prv-probe-run-executor.php index 16c5593..afaa7b3 100644 --- a/includes/core/class-prv-probe-run-executor.php +++ b/includes/core/class-prv-probe-run-executor.php @@ -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 diff --git a/includes/core/class-prv-settings-controller.php b/includes/core/class-prv-settings-controller.php index 6e5edca..98e6bf2 100644 --- a/includes/core/class-prv-settings-controller.php +++ b/includes/core/class-prv-settings-controller.php @@ -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' ) ) diff --git a/includes/panel/class-prv-ai-visibility-panel.php b/includes/panel/class-prv-ai-visibility-panel.php index 752845d..cc3d76f 100644 --- a/includes/panel/class-prv-ai-visibility-panel.php +++ b/includes/panel/class-prv-ai-visibility-panel.php @@ -119,7 +119,7 @@ class PRV_Ai_Visibility_Panel implements PRV_Dashboard_Panel { foreach ( $standings as $row ) { if ( ! empty( $row['cited'] ) ) { - $cited_count++; + ++$cited_count; } } @@ -206,9 +206,9 @@ class PRV_Ai_Visibility_Panel implements PRV_Dashboard_Panel { foreach ( $last_run_counts as $model ) { $status = (string) ( $model['health_status'] ?? 'unknown' ); if ( 'retired' === $status ) { - $retired_count++; + ++$retired_count; } elseif ( 'healthy' === $status ) { - $healthy_count++; + ++$healthy_count; } }