From 12e58b1dd07c01fb23872f785e13768fdb3723e5 Mon Sep 17 00:00:00 2001 From: Jean Paul Galea Date: Thu, 16 Jul 2015 23:17:29 +0200 Subject: [PATCH] Refactor. - merge validation into one block. --- ykval-sync.php | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/ykval-sync.php b/ykval-sync.php index 0c28b34..8005c05 100644 --- a/ykval-sync.php +++ b/ykval-sync.php @@ -109,7 +109,13 @@ $sync->addField('otp', $syncParams['otp']); # Verify correctness of input parameters # -foreach (array('modified') as $param) { +foreach (array('modified','yk_counter', 'yk_use', 'yk_high', 'yk_low') as $param) +{ + // -1 is valid except for modified + if ($param !== 'modified' && $syncParams[$param] === '-1') + continue; + + // [0-9]+ if ($syncParams[$param] !== '' && ctype_digit($syncParams[$param])) continue; @@ -117,19 +123,6 @@ foreach (array('modified') as $param) { sendResp(S_MISSING_PARAMETER, $myLog, $apiKey); } -foreach (array('yk_counter', 'yk_use', 'yk_high', 'yk_low') as $param) { - if ($syncParams[$param] === '-1') - continue; - - if ($syncParams[$param] !== '' && ctype_digit($syncParams[$param])) - continue; - - $myLog->log(LOG_NOTICE, 'Input parameters ' . $param . ' not correct'); - sendResp(S_MISSING_PARAMETER, $myLog, $apiKey); -} - - - # # Get local counter data