From 3606a13ab9241c2839eae48aebbd6ccfb529b098 Mon Sep 17 00:00:00 2001 From: Michael Schiemer Date: Tue, 4 Nov 2025 01:26:27 +0100 Subject: [PATCH] refactor(redis, discovery, cache): streamline configuration defaults, logging, and error handling - Remove default values for `RedisConfig` constructor to enforce explicit configuration. - Enhance `FileStreamProcessor` logging by adding `LogContext` with exception details. - Replace `humanReadable` method call with `toHumanReadable` in `DiscoveryCompletedEvent`. - Remove redundant error trace logging in `CacheInitializer` for cleaner fallback handling. --- src/Framework/Cache/CacheInitializer.php | 1 - .../Discovery/Events/DiscoveryCompletedEvent.php | 5 ++--- .../Discovery/Processing/FileStreamProcessor.php | 4 +++- src/Framework/Redis/RedisConfig.php | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Framework/Cache/CacheInitializer.php b/src/Framework/Cache/CacheInitializer.php index 98c921f7..5b2a9820 100644 --- a/src/Framework/Cache/CacheInitializer.php +++ b/src/Framework/Cache/CacheInitializer.php @@ -68,7 +68,6 @@ final readonly class CacheInitializer // Fallback to file cache if Redis is not available error_log('Redis not available, falling back to file cache: ' . $e->getMessage()); - error_log(print_r($e->getTrace(), true)); $redisCache = new GeneralCache(new FileCache(), $serializer, $compression); } diff --git a/src/Framework/Discovery/Events/DiscoveryCompletedEvent.php b/src/Framework/Discovery/Events/DiscoveryCompletedEvent.php index 518fa246..8c4ea13f 100644 --- a/src/Framework/Discovery/Events/DiscoveryCompletedEvent.php +++ b/src/Framework/Discovery/Events/DiscoveryCompletedEvent.php @@ -20,15 +20,14 @@ final readonly class DiscoveryCompletedEvent public ?ScannerMetrics $metrics, public ScanType $scanType, public Timestamp $timestamp - ) { - } + ) {} public function toArray(): array { return [ 'files_scanned' => $this->filesScanned, 'duration_seconds' => $this->duration->toSeconds(), - 'duration_human' => $this->duration->humanReadable(), + 'duration_human' => $this->duration->toHumanReadable(), 'metrics' => $this->metrics?->toArray(), 'scan_type' => $this->scanType->value, 'timestamp' => $this->timestamp->toFloat(), diff --git a/src/Framework/Discovery/Processing/FileStreamProcessor.php b/src/Framework/Discovery/Processing/FileStreamProcessor.php index 7752f03d..6dbf18dd 100644 --- a/src/Framework/Discovery/Processing/FileStreamProcessor.php +++ b/src/Framework/Discovery/Processing/FileStreamProcessor.php @@ -11,6 +11,7 @@ use App\Framework\Filesystem\ValueObjects\FilePath; use App\Framework\Filesystem\FileScanner; use App\Framework\Filesystem\ValueObjects\FilePattern; use App\Framework\Logging\Logger; +use App\Framework\Logging\ValueObjects\LogContext; use Generator; /** @@ -68,7 +69,8 @@ final readonly class FileStreamProcessor } catch (\Throwable $e) { // Only log errors, not every processed file $this->logger?->warning( - "Failed to process file {$file->getPath()->toString()}: {$e->getMessage()} in FileStreamProcessor" + "Failed to process file {$file->getPath()->toString()}: {$e->getMessage()} in FileStreamProcessor", + LogContext::withException($e) ); } finally { // Always cleanup after processing a file diff --git a/src/Framework/Redis/RedisConfig.php b/src/Framework/Redis/RedisConfig.php index edd39c02..de13a1fb 100644 --- a/src/Framework/Redis/RedisConfig.php +++ b/src/Framework/Redis/RedisConfig.php @@ -13,9 +13,9 @@ use App\Framework\Config\EnvKey; final readonly class RedisConfig { private function __construct( - public string $host = 'redis', - public int $port = 6379, - public ?string $password = null, + public string $host, + public int $port, + public string $password, public int $database = 0, public float $timeout = 1.0, public float $readWriteTimeout = 1.0, @@ -31,9 +31,9 @@ final readonly class RedisConfig public static function fromEnvironment(Environment $env): self { return new self( - host: $env->get(EnvKey::REDIS_HOST, 'redis'), - port: $env->getInt(EnvKey::REDIS_PORT, 6379), - password: $env->get(EnvKey::REDIS_PASSWORD, null), + host: $env->get(EnvKey::REDIS_HOST), + port: $env->getInt(EnvKey::REDIS_PORT), + password: $env->get(EnvKey::REDIS_PASSWORD), database: 0, timeout: 1.0, readWriteTimeout: 1.0,