From 23536666f509cabafee8d94064ecfa1267253327 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 8 Dec 2021 09:52:07 +0000 Subject: Reduce cognitive code complexity --- internal/mapr/whereclause.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'internal') diff --git a/internal/mapr/whereclause.go b/internal/mapr/whereclause.go index d9f32eb..740df71 100644 --- a/internal/mapr/whereclause.go +++ b/internal/mapr/whereclause.go @@ -11,14 +11,7 @@ func (q *Query) WhereClause(fields map[string]string) bool { for _, wc := range q.Where { var ok bool if wc.Operation > FloatOperation { - var lValue, rValue float64 - if lValue, ok = whereClauseFloatValue(fields, wc.lString, wc.lFloat, wc.lType); !ok { - return false - } - if rValue, ok = whereClauseFloatValue(fields, wc.rString, wc.rFloat, wc.rType); !ok { - return false - } - if ok = wc.floatClause(lValue, rValue); !ok { + if !whereClauseFloatValues(fields, wc) { return false } continue @@ -38,6 +31,23 @@ func (q *Query) WhereClause(fields map[string]string) bool { return true } +func whereClauseFloatValues(fields map[string]string, wc whereCondition) bool { + var lValue, rValue float64 + var ok bool + + if lValue, ok = whereClauseFloatValue(fields, wc.lString, wc.lFloat, wc.lType); !ok { + return false + } + if rValue, ok = whereClauseFloatValue(fields, wc.rString, wc.rFloat, wc.rType); !ok { + return false + } + if ok = wc.floatClause(lValue, rValue); !ok { + return false + } + + return true +} + func whereClauseFloatValue(fields map[string]string, str string, float float64, t fieldType) (float64, bool) { -- cgit v1.2.3