Showing 5,781 of 10,536 total issues
Avoid deeply nested control flow statements. Open
if parameters['numerator_meter'] is not None and \
isinstance(parameters['numerator_meter']['uuid'], str) and \
len(str.strip(parameters['numerator_meter']['uuid'])) > 0:
numerator_meter_uuid = str.strip(parameters['numerator_meter']['uuid'])
Avoid deeply nested control flow statements. Open
if meter_dict.get(numerator_meter_uuid) is None and \
virtual_meter_dict.get(numerator_meter_uuid) is None and \
offline_meter_dict.get(numerator_meter_uuid) is None:
cursor.close()
cnx.close()
Function on_get
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def on_get(req, resp, id_):
if 'API-KEY' not in req.headers or \
not isinstance(req.headers['API-KEY'], str) or \
len(str.strip(req.headers['API-KEY'])) == 0:
access_control(req)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
if rows_offline_meters is not None and len(rows_offline_meters) > 0:
for row in rows_offline_meters:
offline_meter_dict[row[2]] = {"type": 'offline_meter',
"id": row[0],
"name": row[1],
Avoid deeply nested control flow statements. Open
if denominator_meter is None:
denominator_meter = virtual_meter_dict.get(row[6], None)
if denominator_meter is None:
Avoid deeply nested control flow statements. Open
if cursor.fetchone() is None:
cursor.close()
cnx.close()
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.POINT_NOT_FOUND')
Avoid deeply nested control flow statements. Open
if denominator_meter_uuid is None:
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_DENOMINATOR_METER_UUID')
Avoid deeply nested control flow statements. Open
if point_id is None:
cursor.close()
cnx.close()
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_POINT_ID')
Function on_delete
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def on_delete(req, resp, id_):
admin_control(req)
if not id_.isdigit() or int(id_) <= 0:
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_CONTACT_ID')
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
for row in rows_virtual_meters:
virtual_meter_dict[row[2]] = {"type": 'virtual_meter',
"id": row[0],
"name": row[1],
"uuid": row[2]}
Avoid deeply nested control flow statements. Open
if denominator_meter is None:
denominator_meter = virtual_meter_dict.get(row[6], None)
if denominator_meter is None:
Avoid deeply nested control flow statements. Open
if rows_meters is not None and len(rows_meters) > 0:
for row in rows_meters:
meter_dict[row[2]] = {"type": 'meter',
"id": row[0],
"name": row[1],
Avoid deeply nested control flow statements. Open
if parameters['point'] is None:
point_id = None
elif parameters['point']['id'] is not None and \
parameters['point']['id'] <= 0:
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
Avoid deeply nested control flow statements. Open
if denominator_meter_uuid == numerator_meter_uuid:
cursor.close()
cnx.close()
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_DENOMINATOR_METER_UUID')
Avoid deeply nested control flow statements. Open
if denominator_meter_uuid not in meter_dict and \
denominator_meter_uuid not in virtual_meter_dict and \
denominator_meter_uuid not in offline_meter_dict:
cursor.close()
cnx.close()
Avoid deeply nested control flow statements. Open
if rows_virtual_meters is not None and len(rows_virtual_meters) > 0:
for row in rows_virtual_meters:
virtual_meter_dict[row[2]] = {"type": 'virtual_meter',
"id": row[0],
"name": row[1],
Function on_post
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def on_post(req, resp, id_):
"""Handles POST requests"""
admin_control(req)
try:
raw_json = req.stream.read().decode('utf-8')
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
for row in rows_offline_meters:
offline_meter_dict[row[2]] = {"type": 'offline_meter',
"id": row[0],
"name": row[1],
"uuid": row[2]}
Avoid deeply nested control flow statements. Open
if denominator_meter is None:
denominator_meter = offline_meter_dict.get(row[6], None)
Avoid deeply nested control flow statements. Open
if parameters['constant'] is None:
cursor.close()
cnx.close()
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_CONSTANT_VALUE')