Skip to content

chore: clean up runtime helper usage#9

Merged
rbcorrales merged 3 commits into
mainfrom
chore/php-runtime-cleanup
May 19, 2026
Merged

chore: clean up runtime helper usage#9
rbcorrales merged 3 commits into
mainfrom
chore/php-runtime-cleanup

Conversation

@rbcorrales
Copy link
Copy Markdown
Member

Summary

This PR removes the low risk runtime helper PHPCS group from the current standards backlog. It replaces discouraged PHP helpers with WordPress equivalents, hoists loop count calls out of for conditions, and routes direct debug log calls through the central WPVDB logger.

It keeps the branch scoped to runtime helper cleanup. Escaping, database query, translator comment, and redirect safety work stay in follow up PRs.

Validation

  • Ran targeted PHPCS runtime helper sniffs across admin, includes, and wpvdb.php.
  • Ran PHP syntax checks on the touched files.
  • Ran git diff --check.

rbcorrales and others added 2 commits May 19, 2026 00:35
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR continues the runtime-helper cleanup by replacing discouraged PHP helpers with WordPress equivalents, reducing repeated count() calls inside loops, and consolidating ad-hoc error_log() usage through the plugin’s centralized WPVDB\Logger.

Changes:

  • Replace parse_url()/json_encode() with wp_parse_url()/wp_json_encode() in runtime/admin/core paths.
  • Hoist count() calls out of loop conditions to avoid repeated evaluations.
  • Route direct error_log() calls through WPVDB\Logger (and add PHPCS ignore where error_log() remains as the centralized sink).

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
includes/wpvdb-runtime.php Switch URL parsing to wp_parse_url() for WordPress-consistent behavior.
includes/class-wpvdb-utils.php Hoist unit count() out of loop condition.
includes/class-wpvdb-settings.php Replace direct error_log() with Logger::critical() for settings diagnostics.
includes/class-wpvdb-security.php Route security debug logging through Logger.
includes/class-wpvdb-rest.php Use wp_json_encode() and route debug/error logs through Logger; minor loop tweak.
includes/class-wpvdb-queue.php Route debug deletion log through Logger.
includes/class-wpvdb-query.php Route query-path debug/error logs through Logger and use wp_json_encode().
includes/class-wpvdb-providers.php Switch URL parsing to wp_parse_url().
includes/class-wpvdb-plugin.php Route deactivation debug log through Logger.
includes/class-wpvdb-logger.php Add PHPCS ignore to the centralized error_log() sink.
includes/class-wpvdb-database.php Route DB capability diagnostics through Logger.
includes/class-wpvdb-core.php Use wp_json_encode() for non-string payload normalization.
includes/class-wpvdb-cache.php Route cache debug logs through Logger and remove redundant WP_DEBUG nesting.
includes/class-wpvdb-admin.php Route admin debug logs through Logger; use wp_json_encode().
includes/class-wpvdb-activation.php Route activation/upgrade diagnostics through Logger.
admin/views/status.php Replace print_r() output with pretty JSON for display.
admin/views/embeddings.php Replace error_log() with \WPVDB\Logger and use wp_json_encode() for debug serialization.
Comments suppressed due to low confidence (5)

includes/class-wpvdb-query.php:157

  • Database errors are currently logged with Logger::debug(). Since Logger routes to wpvdb_should_log_to_error_log using the provided $level, consider logging $wpdb->last_error via Logger::error() so it can be surfaced when wpvdb_log_level is set to error (and for consumers filtering by level).
					if ( $wpdb->last_error ) {
						Logger::debug( 'Database error in vector search: ' . $wpdb->last_error );
					}

includes/class-wpvdb-query.php:170

  • Exceptions in the vector search path are logged at debug level. These represent failures to execute the search and are usually better captured via Logger::error() (or at least warning()) so they aren't dropped when only error+ logs are retained.
				} catch ( \Exception $e ) {
					Logger::debug( 'Exception in vector search: ' . $e->getMessage() );
				}

includes/class-wpvdb-query.php:212

  • The catch-all 'Unhandled exception' is logged via Logger::debug(). Consider Logger::error() here so unexpected failures remain visible when the log level is configured above debug.
		} catch ( \Exception $e ) {
			Logger::debug( 'Unhandled exception in maybe_vector_search: ' . $e->getMessage() );
		}

includes/class-wpvdb-activation.php:326

  • A catch-all "Fatal error" is currently logged with Logger::debug(). This should likely be Logger::critical() or Logger::error() so it isn't filtered out by minimum log level settings.
		} catch ( \Exception $e ) {
			// Catch all exceptions to prevent activation failure.
			Logger::debug( 'Fatal error in add_vector_index_to_existing_table: ' . $e->getMessage() );
			return false;

includes/class-wpvdb-activation.php:285

  • The fallback index creation path logs success/failure at debug level. For the failure branch (uses $wpdb->last_error), consider Logger::error() so operational issues are not silently dropped by minimum log level settings.
							if ( false !== $result ) {
								Logger::debug( 'Added vector index with simplified syntax' );
							} else {
								Logger::debug( 'Failed to add vector index with simplified syntax: ' . $wpdb->last_error );
							}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread includes/class-wpvdb-query.php
Comment thread includes/class-wpvdb-settings.php Outdated
Comment thread includes/class-wpvdb-security.php Outdated
Comment thread includes/class-wpvdb-activation.php
Co-authored-by: Codex <noreply@openai.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated no new comments.

@rbcorrales rbcorrales merged commit 59cec52 into main May 19, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants