Files
roi-theme/Shared/Infrastructure/Validators/ValidationResult.php
FrankZamora 90863cd8f5 fix(structure): Correct case-sensitivity for Linux compatibility
Rename folders to match PHP PSR-4 autoloading conventions:
- schemas → Schemas
- shared → Shared
- Wordpress → WordPress (in all locations)

Fixes deployment issues on Linux servers where filesystem is case-sensitive.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 22:53:34 -06:00

158 lines
3.3 KiB
PHP

<?php
declare(strict_types=1);
namespace ROITheme\Shared\Infrastructure\Validators;
/**
* Resultado de una validación
*
* Almacena errores, advertencias, información y estadísticas
*/
final class ValidationResult
{
/**
* @param bool $success Estado inicial de éxito
* @param array<string> $errors Lista de errores críticos
* @param array<string> $warnings Lista de advertencias
* @param array<string> $info Lista de mensajes informativos
* @param array<string, mixed> $stats Estadísticas de la validación
*/
public function __construct(
private bool $success = true,
private array $errors = [],
private array $warnings = [],
private array $info = [],
private array $stats = []
) {}
/**
* Verifica si la validación fue exitosa
*
* @return bool True si no hay errores, false si hay al menos un error
*/
public function isSuccess(): bool
{
return $this->success && empty($this->errors);
}
/**
* Obtiene todos los errores críticos
*
* @return array<string>
*/
public function getErrors(): array
{
return $this->errors;
}
/**
* Obtiene todas las advertencias
*
* @return array<string>
*/
public function getWarnings(): array
{
return $this->warnings;
}
/**
* Obtiene todos los mensajes informativos
*
* @return array<string>
*/
public function getInfo(): array
{
return $this->info;
}
/**
* Obtiene todas las estadísticas
*
* @return array<string, mixed>
*/
public function getStats(): array
{
return $this->stats;
}
/**
* Agrega un error crítico
*
* Al agregar un error, la validación se marca como fallida
*
* @param string $message Mensaje del error
* @return void
*/
public function addError(string $message): void
{
$this->errors[] = $message;
$this->success = false;
}
/**
* Agrega una advertencia
*
* Las advertencias NO marcan la validación como fallida
*
* @param string $message Mensaje de advertencia
* @return void
*/
public function addWarning(string $message): void
{
$this->warnings[] = $message;
}
/**
* Agrega un mensaje informativo
*
* @param string $message Mensaje informativo
* @return void
*/
public function addInfo(string $message): void
{
$this->info[] = $message;
}
/**
* Establece una estadística
*
* @param string $key Clave de la estadística
* @param mixed $value Valor de la estadística
* @return void
*/
public function setStat(string $key, mixed $value): void
{
$this->stats[$key] = $value;
}
/**
* Cuenta total de errores
*
* @return int
*/
public function getErrorCount(): int
{
return count($this->errors);
}
/**
* Cuenta total de advertencias
*
* @return int
*/
public function getWarningCount(): int
{
return count($this->warnings);
}
/**
* Marca la validación como fallida manualmente
*
* @return void
*/
public function markAsFailed(): void
{
$this->success = false;
}
}