Showing 195 of 195 total issues
Avoid too many return
statements within this function. Open
return error_response('Stack with id %s does not exist' % stack_name, code=404)
Similar blocks of code found in 2 locations. Consider refactoring. Open
result = list(filter(lambda api: api['name'] == resource_id, apis))
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 32.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Function map_all_s3_objects
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def map_all_s3_objects(to_json=True):
s3_client = get_s3_client()
result = {}
for bucket in s3_client.buckets.all():
for key in bucket.objects.all():
- 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
Function resources_to_deploy_next
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def resources_to_deploy_next(resources, stack_name):
result = {}
for resource_id, resource in iteritems(resources):
if is_deployable_resource(resource) and not is_deployed(resource_id, resources, stack_name):
res_deps = get_resource_dependencies(resource_id, resource, resources)
- 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
Function invoke_function
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def invoke_function(function):
""" Invoke an existing function
---
operationId: 'invokeFunction'
parameters:
- 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
Function use_docker
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def use_docker():
global DO_USE_DOCKER
if DO_USE_DOCKER is None:
DO_USE_DOCKER = False
if config.LAMBDA_EXECUTOR == 'docker':
- 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
Function parse_request
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def parse_request(self):
result = BaseHTTPRequestHandler.parse_request(self)
if not result:
return result
if sys.version_info[0] >= 3:
- 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
Function update_destination
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def update_destination(stream_name, destination_id,
s3_update=None, elasticsearch_update=None, version_id=None):
dest = get_destination(stream_name, destination_id)
if elasticsearch_update:
print('WARN: Firehose to Elasticsearch updates not yet implemented!')
- 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
Function aws_cmd
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def aws_cmd(service, env):
# TODO: use boto3 instead of running aws-cli commands here!
cmd = '{ test `which aws` || . .venv/bin/activate; }; aws'
endpoint_url = None
- 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
Function get_subscription_by_arn
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def get_subscription_by_arn(sub_arn):
# TODO maintain separate map instead of traversing all items
for key, subscriptions in SNS_SUBSCRIPTIONS.items():
for sub in subscriptions:
if sub['SubscriptionArn'] == sub_arn:
- 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
Function cleanup_tmp_files
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def cleanup_tmp_files():
for tmp in TMP_FILES:
try:
if os.path.isdir(tmp):
run('rm -rf "%s"' % tmp)
- 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
Function get_logger_for_level_in_log_line
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def get_logger_for_level_in_log_line(self, line):
level = self.log_level
for l in LOG_LEVELS:
if l >= level:
level_name = logging.getLevelName(l)
- 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
Function do_run
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def do_run(cmd, async, print_output=False):
sys.stdout.flush()
if async:
if is_debug():
print_output = True
- 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
Function all_dependencies_satisfied
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def all_dependencies_satisfied(resources, stack_name, all_resources, depending_resource=None):
for resource_id, resource in iteritems(resources):
if is_deployable_resource(resource):
if not is_deployed(resource_id, all_resources, stack_name):
return False
- 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
Function get_event_sources
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def get_event_sources(func_name=None, source_arn=None):
result = []
for m in event_source_mappings:
if not func_name or m['FunctionArn'] in [func_name, func_arn(func_name)]:
if not source_arn or m['EventSourceArn'].startswith(source_arn):
- 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"