* * Ejemplos: * php shared/Infrastructure/Scripts/validate-architecture.php top-notification-bar * php shared/Infrastructure/Scripts/validate-architecture.php navbar * php shared/Infrastructure/Scripts/validate-architecture.php hero-section * * Códigos de salida: * 0 = Validación exitosa (sin errores) * 1 = Validación fallida (errores encontrados) */ declare(strict_types=1); // Validar argumentos if ($argc < 2) { echo "❌ Error: Falta nombre del componente\n\n"; echo "Uso: php shared/Infrastructure/Scripts/validate-architecture.php \n\n"; echo "Ejemplos:\n"; echo " php shared/Infrastructure/Scripts/validate-architecture.php top-notification-bar\n"; echo " php shared/Infrastructure/Scripts/validate-architecture.php navbar\n"; exit(1); } $componentName = $argv[1]; // Determinar ruta al tema (3 niveles arriba desde Scripts/) $themePath = dirname(__DIR__, 3); // Cargar WordPress $wpLoadPath = dirname($themePath, 3) . '/wp-load.php'; if (!file_exists($wpLoadPath)) { echo "❌ Error: No se pudo cargar WordPress\n"; echo "Ruta esperada: {$wpLoadPath}\n"; echo "Asegúrate de ejecutar el script desde el directorio del tema\n"; exit(1); } require_once $wpLoadPath; // Cargar validadores manualmente $validatorsPath = __DIR__ . '/../Validators/'; require_once $validatorsPath . 'ValidationResult.php'; require_once $validatorsPath . 'PhaseValidatorInterface.php'; require_once $validatorsPath . 'FolderStructureValidator.php'; require_once $validatorsPath . 'Phase01Validator.php'; require_once $validatorsPath . 'Phase02Validator.php'; require_once $validatorsPath . 'Phase03Validator.php'; require_once $validatorsPath . 'Phase04Validator.php'; require_once $validatorsPath . 'Phase05Validator.php'; require_once $validatorsPath . 'CSSConflictValidator.php'; require_once $validatorsPath . 'TemplateCallsValidator.php'; use ROITheme\Shared\Infrastructure\Validators\FolderStructureValidator; use ROITheme\Shared\Infrastructure\Validators\Phase01Validator; use ROITheme\Shared\Infrastructure\Validators\Phase02Validator; use ROITheme\Shared\Infrastructure\Validators\Phase03Validator; use ROITheme\Shared\Infrastructure\Validators\Phase04Validator; use ROITheme\Shared\Infrastructure\Validators\Phase05Validator; use ROITheme\Shared\Infrastructure\Validators\CSSConflictValidator; use ROITheme\Shared\Infrastructure\Validators\TemplateCallsValidator; // Header printHeader($componentName); // Crear validadores $validators = [ new FolderStructureValidator(), // Estructura de carpetas (base) new Phase01Validator(), // Schema JSON new Phase02Validator(), // JSON→BD Sync new Phase03Validator(), // Renderers new Phase04Validator(), // FormBuilders new Phase05Validator(), // General SOLID (todos los archivos) new CSSConflictValidator(), // Conflictos CSS (Assets vs Renderers dinámicos) new TemplateCallsValidator(), // Llamadas roi_render_component() en templates ]; // Ejecutar validaciones $allSuccess = true; $totalErrors = 0; $totalWarnings = 0; foreach ($validators as $validator) { $result = $validator->validate($componentName, $themePath); // Imprimir resultado printValidationResult($validator, $result); if (!$result->isSuccess()) { $allSuccess = false; } $totalErrors += $result->getErrorCount(); $totalWarnings += $result->getWarningCount(); echo "\n"; } // Resumen final printSummary($allSuccess, $totalErrors, $totalWarnings); // Código de salida exit($allSuccess ? 0 : 1); /** * Imprime el header del script */ function printHeader(string $componentName): void { echo "\n"; echo "╔═══════════════════════════════════════════════════════════╗\n"; echo "║ ARCHITECTURE VALIDATOR - ROI THEME ║\n"; echo "╚═══════════════════════════════════════════════════════════╝\n"; echo "\n"; echo "Validando componente: {$componentName}\n"; echo "\n"; } /** * Imprime el resultado de una validación */ function printValidationResult($validator, $result): void { echo "═══════════════════════════════════════════════════════════\n"; echo "FASE {$validator->getPhaseNumber()}: {$validator->getPhaseDescription()}\n"; echo "═══════════════════════════════════════════════════════════\n"; // Info messages if (!empty($result->getInfo())) { foreach ($result->getInfo() as $info) { echo "ℹ️ {$info}\n"; } } // Stats if (!empty($result->getStats())) { echo "\n📊 Estadísticas:\n"; foreach ($result->getStats() as $key => $value) { echo " • {$key}: {$value}\n"; } } // Warnings if (!empty($result->getWarnings())) { echo "\n⚠️ ADVERTENCIAS:\n"; foreach ($result->getWarnings() as $warning) { echo " • {$warning}\n"; } } // Errors if (!empty($result->getErrors())) { echo "\n❌ ERRORES CRÍTICOS:\n"; foreach ($result->getErrors() as $error) { echo " • {$error}\n"; } } // Result echo "\n"; if ($result->isSuccess()) { echo "✅ FASE {$validator->getPhaseNumber()}: EXITOSA\n"; } else { echo "❌ FASE {$validator->getPhaseNumber()}: FALLIDA ({$result->getErrorCount()} errores)\n"; } } /** * Imprime el resumen final */ function printSummary(bool $allSuccess, int $totalErrors, int $totalWarnings): void { echo "\n"; echo "╔═══════════════════════════════════════════════════════════╗\n"; echo "║ RESUMEN FINAL ║\n"; echo "╚═══════════════════════════════════════════════════════════╝\n"; echo "\n"; echo "Total errores: {$totalErrors}\n"; echo "Total advertencias: {$totalWarnings}\n"; echo "\n"; if ($allSuccess) { echo "✅ ¡VALIDACIÓN EXITOSA!\n"; echo "El componente cumple con todos los estándares arquitectónicos.\n"; } else { echo "❌ VALIDACIÓN FALLIDA\n"; echo "Corregir errores críticos antes de continuar.\n"; echo "\n"; echo "Acciones recomendadas:\n"; echo " • Revisar errores arriba\n"; echo " • Corregir violaciones arquitectónicas\n"; echo " • Ejecutar validación nuevamente\n"; } echo "\n"; }