mangroveorg/datawinners

View on GitHub
datawinners/entity/helper.py

Summary

Maintainability
D
2 days
Test Coverage

Function get_field_instruction has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

def get_field_instruction(field):
    if type(field) == ShortCodeField and field.constraint[0].max == 20:
        instruction = ugettext("Answer must be 20 characters maximum")

    if type(field) == TextField:
Severity: Minor
Found in datawinners/entity/helper.py - About 3 hrs to fix

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

File helper.py has 282 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# vim: ai ts=4 sts=4 et sw=4 encoding=utf-8
from collections import OrderedDict
import re
import logging
from django.db import IntegrityError
Severity: Minor
Found in datawinners/entity/helper.py - About 2 hrs to fix

    Function process_create_data_sender_form has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def process_create_data_sender_form(dbm, form, org_id):
        message = None
        data_sender_id = None
    
        if form.is_valid():
    Severity: Minor
    Found in datawinners/entity/helper.py - About 1 hr to fix

    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_subject_field_instruction has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_subject_field_instruction(field, entity_type):
        if field.name == FIRSTNAME_FIELD:
            instruction = _("Enter a %(entity_type)s first name") % {'entity_type': entity_type}
        elif field.name == NAME_FIELD:
            instruction = _("Enter a %(entity_type)s last name") % {'entity_type': entity_type}
    Severity: Minor
    Found in datawinners/entity/helper.py - About 35 mins to fix

    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 add_imported_data_sender_to_trial_organization has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def add_imported_data_sender_to_trial_organization(org_id, imported_datasenders, all_data_senders, index=0):
        organization = Organization.objects.get(org_id=org_id)
        if organization.in_trial_mode:
            mobile_number_index = index
            for ds in all_data_senders:
    Severity: Minor
    Found in datawinners/entity/helper.py - About 25 mins to fix

    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

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        question1 = TextField(name=FIRSTNAME_FIELD, code=code_generator.next(),
            label=_("What is the %(entity_type)s's first name?") % {'entity_type': entity_name},
            defaultValue="some default value",
            instruction=_("Enter a %(entity_type)s first name") % {'entity_type': entity_name})
    Severity: Major
    Found in datawinners/entity/helper.py and 1 other location - About 2 hrs to fix
    datawinners/entity/helper.py on lines 82..85

    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 55.

    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

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        question2 = TextField(name=NAME_FIELD, code=code_generator.next(),
            label=_("What is the %(entity_type)s's last name?") % {'entity_type': entity_name},
            defaultValue="some default value",
            instruction=_("Enter a %(entity_type)s last name") % {'entity_type': entity_name})
    Severity: Major
    Found in datawinners/entity/helper.py and 1 other location - About 2 hrs to fix
    datawinners/entity/helper.py on lines 77..80

    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 55.

    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

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        question3 = HierarchyField(name=LOCATION_TYPE_FIELD_NAME, code=code_generator.next(),
            label=_("What is the %(entity_type)s's location?") % {'entity_type': entity_name}, instruction=unicode(_("Enter a region, district, or commune")))
    Severity: Major
    Found in datawinners/entity/helper.py and 1 other location - About 1 hr to fix
    datawinners/entity/helper.py on lines 88..90

    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 46.

    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

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        question4 = GeoCodeField(name=GEO_CODE_FIELD_NAME, code=code_generator.next(),
            label=_("What is the %(entity_type)s's GPS co-ordinates?") % {'entity_type': entity_name},
            instruction=unicode(_("Answer must be GPS coordinates in the following format (latitude,longitude). Example: -18.1324,27.6547")))
    Severity: Major
    Found in datawinners/entity/helper.py and 1 other location - About 1 hr to fix
    datawinners/entity/helper.py on lines 86..87

    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 46.

    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

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    def _add_data_sender_to_trial_organization(telephone_number, org_id):
        data_sender = DataSenderOnTrialAccount.objects.model(mobile_number=telephone_number,
            organization=Organization.objects.get(org_id=org_id))
        data_sender.save(force_insert=True)
    Severity: Major
    Found in datawinners/entity/helper.py and 1 other location - About 1 hr to fix
    datawinners/accountmanagement/models.py on lines 310..314

    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 40.

    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

    Further Reading

    There are no issues that match your filters.

    Category
    Status