spicycms/spicy.core

View on GitHub
src/spicy/core/profile/views.py

Summary

Maintainability
D
2 days
Test Coverage

Function new_social_user has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

def new_social_user(request):
    new_user = request.session.get('NEW_USER')
    if not new_user:
        return HttpResponseRedirect(reverse('profile:public:signin'))
    elif not (new_user.is_active and new_user.is_authenticated()):
Severity: Minor
Found in src/spicy/core/profile/views.py - About 6 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 views.py has 285 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
import random
import string
import logging
from uuid import uuid4
Severity: Minor
Found in src/spicy/core/profile/views.py - About 2 hrs to fix

    Function sa_set_new_user_inactive has 8 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def sa_set_new_user_inactive(
    Severity: Major
    Found in src/spicy/core/profile/views.py - About 1 hr to fix

      Function set_email has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      def set_email(request):
          if request.user.email:
              return {'msg': _('Email address is already set')}
          if request.method == 'POST':
              form = forms.SetEmailForm(request.POST)
      Severity: Minor
      Found in src/spicy/core/profile/views.py - About 45 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

      Avoid deeply nested control flow statements.
      Open

                          if not redirect_to:
                              return {'msg': _('Validation email has been sent')}
                      return HttpResponseRedirect(
      Severity: Major
      Found in src/spicy/core/profile/views.py - About 45 mins to fix

        Avoid too many return statements within this function.
        Open

            return {
        Severity: Major
        Found in src/spicy/core/profile/views.py - About 30 mins to fix

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

          def signin(request):
              result = api.register['profile'].login(request)
              if result['status'] == 'ok':
                  return HttpResponseRedirect(
                      result.get('redirect') or user_redirect_uri)
          Severity: Minor
          Found in src/spicy/core/profile/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

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

          @render_to('spicy.core.profile/widgets/signin_form.html')
          def login_widget(request):
              result = api.register['profile'].login(request)
              if result['status'] == 'ok':
                  result['redirect_now'] = True
          Severity: Major
          Found in src/spicy/core/profile/views.py and 1 other location - About 2 hrs to fix
          src/spicy/core/profile/views.py on lines 214..219

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

          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

          @render_to('spicy.core.profile/widgets/signup_form.html')
          def registration_widget(request):
              result = api.register['profile'].register(request)
              if result['status'] == 'ok':
                  result['redirect_now'] = True
          Severity: Major
          Found in src/spicy/core/profile/views.py and 1 other location - About 2 hrs to fix
          src/spicy/core/profile/views.py on lines 206..211

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

          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