From 196e7fe2630a7ce175d5fc1e16b6dc03f9d4d313 Mon Sep 17 00:00:00 2001 From: aguilita1 Date: Fri, 15 Nov 2024 22:11:35 -0500 Subject: [PATCH] Fix cast errors (#27) * Fixed cast errors with environment variables and update PHPDoc --------- Co-authored-by: Daniel I. Kelley --- src/main.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main.php b/src/main.php index b752be7..0585f73 100644 --- a/src/main.php +++ b/src/main.php @@ -22,10 +22,15 @@ use SampleSyncApp\Utils; // Load configuration from environment variables -$syncInterval = (int)($_SERVER['SA_SYNC_INTERVAL'] ?? 60); -$syncStart = $_SERVER['SA_START_SYNC'] ?? '00:00:00'; -$syncEnd = $_SERVER['SA_STOP_SYNC'] ?? '23:59:59'; -date_default_timezone_set($_SERVER['SA_TIME_ZONE'] ?? 'UTC'); +$syncInterval = isset($_SERVER['SA_SYNC_INTERVAL']) + ? (int)filter_var($_SERVER['SA_SYNC_INTERVAL'], FILTER_VALIDATE_INT) : 60; +$syncStart = isset($_SERVER['SA_START_SYNC']) && is_string($_SERVER['SA_START_SYNC']) + ? (string)$_SERVER['SA_START_SYNC'] : '00:00:00'; +$syncEnd = isset($_SERVER['SA_STOP_SYNC']) && is_string($_SERVER['SA_STOP_SYNC']) + ? (string)$_SERVER['SA_STOP_SYNC'] : '23:59:59'; +$timezone = isset($_SERVER['SA_TIME_ZONE']) && is_string($_SERVER['SA_TIME_ZONE']) + ? (string)$_SERVER['SA_TIME_ZONE'] : 'UTC'; +date_default_timezone_set($timezone); // Initialize Logger $log = initializeLogger(); @@ -34,7 +39,7 @@ $log->info(sprintf('Starting up - SampleSyncApp version: %s PROJECT_ROOT=%s', 'APP_VERSION', PROJECT_ROOT)); $log->debug('*****************START**main.php*********************'); - /** @var React\EventLoop\LoopInterface $loop */ + /** @var React\EventLoop\StreamSelectLoop $loop */ $loop = new StreamSelectLoop(); $loop->addPeriodicTimer($syncInterval, function () use ($log, $syncInterval, $syncStart, $syncEnd) {