1
0
mirror of https://github.com/Yubico/yubikey-val.git synced 2025-02-27 06:54:16 +01:00

Refactor.

- negate test and return early.

- avoid wrapping whole function in `if () { }`.

- move $condition below $arr,
	since $arr is passwed first, then $condition, to conditionalUpdateBy().
This commit is contained in:
Jean Paul Galea 2015-07-20 19:53:45 +00:00
parent 3097d13629
commit 5ed2f1d4d5

View File

@ -195,9 +195,8 @@ class SyncLib
public function updateDbCounters($params) public function updateDbCounters($params)
{ {
if (isset($params['yk_publicname'])) if (!isset($params['yk_publicname']))
{ return false;
$condition = '('.$params['yk_counter'].'>yk_counter or ('.$params['yk_counter'].'=yk_counter and ' . $params['yk_use'] . '>yk_use))';
$arr = array( $arr = array(
'modified' => $params['modified'], 'modified' => $params['modified'],
@ -208,6 +207,8 @@ class SyncLib
'nonce' => $params['nonce'] 'nonce' => $params['nonce']
); );
$condition = '('.$params['yk_counter'].'>yk_counter or ('.$params['yk_counter'].'=yk_counter and ' . $params['yk_use'] . '>yk_use))';
if (! $this->db->conditionalUpdateBy('yubikeys', 'yk_publicname', $params['yk_publicname'], $arr, $condition)) if (! $this->db->conditionalUpdateBy('yubikeys', 'yk_publicname', $params['yk_publicname'], $arr, $condition))
{ {
$this->log(LOG_CRIT, 'failed to update internal DB with new counters'); $this->log(LOG_CRIT, 'failed to update internal DB with new counters');
@ -222,9 +223,6 @@ class SyncLib
return true; return true;
} }
return false;
}
public function countersHigherThan($p1, $p2) public function countersHigherThan($p1, $p2)
{ {
if ($p1['yk_counter'] > $p2['yk_counter']) if ($p1['yk_counter'] > $p2['yk_counter'])