codeforamerica/intake

View on GitHub

Showing 146 of 168 total issues

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

        if count == 0:
            context['no_results'] = "There are no CNL applications!"
        else:
            context['no_results'] = None
Severity: Minor
Found in intake/views/admin_views.py and 1 other location - About 35 mins to fix
intake/views/admin_views.py on lines 183..186

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

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

@then("it should load the applicant's edit page")
def test_edit_page_loads(context):
    step_text = 'Then it should load "application/{}/edit"'\
        .format(SEARCHABLE_APPLICANT_ID)
    context.execute_steps(step_text)
Severity: Minor
Found in features/steps/applications_steps.py and 1 other location - About 30 mins to fix
features/steps/applications_steps.py on lines 173..177

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

Further Reading

Avoid too many return statements within this function.
Open

            return self.request_valid(request, *args, **kwargs)
Severity: Major
Found in intake/views/base_views.py - About 30 mins to fix

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

    class HowLongCaliforniaResident(CharField):
        context_key = "how_long_california_resident"
        label = _(
            "If you live in California, how long have you continuously lived "
            "here?")
    Severity: Major
    Found in formation/fields.py and 3 other locations - About 30 mins to fix
    formation/fields.py on lines 321..329
    formation/fields.py on lines 332..338
    formation/fields.py on lines 382..386

    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

    Further Reading

    Avoid too many return statements within this function.
    Open

            return Response(data=updated_tags, status=201)
    Severity: Major
    Found in intake/views/tag_views.py - About 30 mins to fix

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

      @then("it should load the applicant's detail page")
      def test_detail_page_loads(context):
          step_text = 'Then it should load "application/{}/"'.format(
              SEARCHABLE_APPLICANT_ID)
          context.execute_steps(step_text)
      Severity: Minor
      Found in features/steps/applications_steps.py and 1 other location - About 30 mins to fix
      features/steps/applications_steps.py on lines 225..229

      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

      Further Reading

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

      class PhoneNumberField(PhoneField):
          context_key = "phone_number"
          help_text = _('For example, (555) 555-5555')
          label = _('What is your phone number?')
          autocomplete = "tel"
      Severity: Major
      Found in formation/fields.py and 3 other locations - About 30 mins to fix
      formation/fields.py on lines 321..329
      formation/fields.py on lines 332..338
      formation/fields.py on lines 474..480

      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

      Further Reading

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

      class DriverLicenseOrIDNumber(CharField):
          context_key = "driver_license_or_id"
          label = _("What is your Driver License or ID number? (if you have one)")
          help_text = _(
              "This helps identify your case from people who have a "
      Severity: Major
      Found in formation/fields.py and 3 other locations - About 30 mins to fix
      formation/fields.py on lines 321..329
      formation/fields.py on lines 382..386
      formation/fields.py on lines 474..480

      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

      Further Reading

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

      class LastFourOfSocial(CharField):
          context_key = "last_four"
          label = _(
              'What are the last 4 digits of your Social Security Number? '
              '(if you have one)')
      Severity: Major
      Found in formation/fields.py and 3 other locations - About 30 mins to fix
      formation/fields.py on lines 332..338
      formation/fields.py on lines 382..386
      formation/fields.py on lines 474..480

      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

      Further Reading

      Function notify_applicant has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def notify_applicant(self, unsafe_data_diff):
              profile = self.request.user.profile
              org = profile.organization
              name = safestring.mark_safe('the ' + org.name if org.slug != 'cfa' else org.name)
              contact_info = safestring.mark_safe(org.get_contact_info_message())
      Severity: Minor
      Found in intake/views/app_edit_view.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

      Function get_context_data has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_context_data(self, *args, **kwargs):
              context = super().get_context_data(*args, **kwargs)
              self.submission = self.submissions[0]
              display_form, letter_display = \
                  DisplayFormService.get_display_form_for_user_and_submission(
      Severity: Minor
      Found in intake/views/app_detail_views.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

      Function get_contact_info has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_contact_info(self):
              """Returns a dictionary of contact information structured to
              be valid for intake.fields.ContactInfoJSONField
              """
              info = {}
      Severity: Minor
      Found in intake/models/form_submission.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

      Function handle has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def handle(self, *args, **kwargs):
              for domain in kwargs['domains']:
                  for path in URLS_SHOULD_200:
                      url = urljoin(domain, path)
                      r = requests.get(url)
      Severity: Minor
      Found in intake/management/commands/test_urls_200.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

      Function log_multiple has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def log_multiple(cls, event_type, submission_ids,
                           user, time=None, organization=None,
                           organization_id=None):
              if not time:
                  time = timezone_utils.now()
      Severity: Minor
      Found in intake/models/application_log_entry.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

      Function process_request has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def process_request(self, request):
              if not is_a_monitoring_request(request):
                  referrer = request.META.get('HTTP_REFERER')
                  if referrer:
                      referrer_host = urlparse(referrer).netloc
      Severity: Minor
      Found in intake/middleware.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

      Function init_templates has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def init_templates(self):
              if not jinja.env:
                  raise JinjaNotInitializedError(
                      "the jinja environment has not been initialized")
              for key, value in self.template_and_path_args.items():
      Severity: Minor
      Found in intake/notifications.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

      Function to_representation has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def to_representation(self, app, *args, **kwargs):
              app_fields = super().to_representation(app, *args, **kwargs)
              display_form, letter = get_display_form_for_csv_download(app)
              data = OrderedDict(id=app.form_submission_id)
              data['Link'] = app.form_submission.get_external_url()
      Severity: Minor
      Found in intake/serializers/application_serializers.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

      Function total_display_data has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      def total_display_data(total_app_data_by_week, year_weeks):
          """
          Generate a dictionary of data suitable for our view to render total stats
          across all organizations that receive applications. It includes metadata
          about the organization whose stats are being displayed, a cumulative total
      Severity: Minor
      Found in intake/services/statistics.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

      Function validate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def validate(self):
              """Run validation method on each subfield,
              update `.errors` with `subfield.errors`,
              and then run the validators for this parent field
              """
      Severity: Minor
      Found in formation/field_types.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

      Function copy_answers_data_to_model_fields has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      def copy_answers_data_to_model_fields(submission):
          """Copies data from a form submission's answers json into it's model fields
          """
          keys = (
              FORMSUBMISSION_TEXT_SEARCH_FIELDS + QUERYABLE_ANSWER_FIELDS +
      Severity: Minor
      Found in intake/services/submissions.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

      Severity
      Category
      Status
      Source
      Language