Files
pr-vision/includes/core/class-prv-autoloader.php
peptiderepo 68ae5b9b1a 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
2026-06-13 09:42:55 +00:00

71 lines
1.8 KiB
PHP

<?php
/** @package PrVision */
declare(strict_types=1);
/**
* Class and interface autoloader for the PR Vision plugin.
*
* Converts PRV_* class/interface names to file paths under includes/.
* Naming conventions:
* PRV_Foo_Bar (class) → class-prv-foo-bar.php
* PRV_Foo_Bar (interface) → interface-prv-foo-bar.php (tried second)
*
* Who triggers: Plugin boot (pr-vision.php) — called once before
* any PRV_* class or interface is instantiated.
* Dependencies: None (pure PHP).
*
* @package PrVision
*/
class PRV_Autoloader {
/**
* Register the autoloader with the SPL stack.
*
* @return void
*/
public static function register(): void {
spl_autoload_register( array( static::class, 'load' ) );
}
/**
* Attempt to load a PRV_* class or interface file.
*
* Walks the known include subdirectories in order, trying the class-
* filename first and the interface-filename second.
*
* Side effects: require_once on a matching file.
*
* @param string $class_name Fully-qualified class or interface name.
*
* @return void
*/
public static function load( string $class_name ): void {
if ( 0 !== strpos( $class_name, 'PRV_' ) ) {
return;
}
$slug = strtolower( str_replace( '_', '-', $class_name ) );
$search_dirs = array(
PRV_PLUGIN_DIR . 'includes/core/',
PRV_PLUGIN_DIR . 'includes/providers/',
PRV_PLUGIN_DIR . 'includes/collector/',
PRV_PLUGIN_DIR . 'includes/panel/',
PRV_PLUGIN_DIR . 'includes/',
);
// Try class file first, then interface file.
$candidates = array( 'class-' . $slug . '.php', 'interface-' . $slug . '.php' );
foreach ( $search_dirs as $dir ) {
foreach ( $candidates as $file ) {
$path = $dir . $file;
if ( file_exists( $path ) ) {
require_once $path;
return;
}
}
}
}
}