tuomas2/serviceform

View on GitHub

Showing 197 of 197 total issues

Function _fetch_instances has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def _fetch_instances(self) -> None:
        categories = [self.category] if self.category else self.form.sub_items

        for cat1 in categories:
            for cat2 in cat1.sub_items:
Severity: Minor
Found in serviceform/serviceform/forms.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_form has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def get_form(self, request: HttpRequest, obj: models.ServiceForm=None, **kwargs):
        form = super().get_form(request, obj, **kwargs)
        if obj:
            request._responsibles = responsibles = models.ResponsibilityPerson.objects.filter(
                form=obj)
Severity: Minor
Found in serviceform/serviceform/admin.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 color_style has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

def color_style(item: 'AbstractServiceFormItem', lighter=0, attr='background') -> SafeString:
    color = item.background_color_display
    if color:
        if lighter < 0:
            for i in range(-lighter):
Severity: Minor
Found in serviceform/serviceform/templatetags/serviceform_tags.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 checkForm has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    var checkForm = function(evt) {

      var isFieldDirty = function($field) {
        var origValue = $field.data('ays-orig');
        if (undefined === origValue) {
Severity: Minor
Found in serviceform/serviceform/static/jquery.are-you-sure.js - About 1 hr to fix

    Function can_access_view has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def can_access_view(self, view_name: str, auth: bool=False) -> bool:
            """
                Access is granted to next view after last finished view
    
                auth: if query is for authentication (if we can already really proceed to view or not).
    Severity: Minor
    Found in serviceform/serviceform/models/people.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 serviceform has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def serviceform(function=None, check_form_permission=False, init_counters=False,
                    all_responsibles=True, fetch_participants=False):
        def actual_decorator(func):
            @wraps(func)
            def wrapper(request: HttpRequest, slug: str,
    Severity: Minor
    Found in serviceform/serviceform/views/decorators.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 participant_flow_menu_items has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def participant_flow_menu_items(context: Context) -> List[FlowItem]:
        current_view = context['request'].resolver_match.view_name
        participant = context['request'].participant
        cat_num = context.get('cat_num', 0)
        lst = []
    Severity: Minor
    Found in serviceform/serviceform/templatetags/serviceform_tags.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_field_change has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_field_change(self, form, changed_fields):
            """Mentions old and new value for changed fields"""
            changes = []
            for field_name in changed_fields:
                field = form.fields[field_name]
    Severity: Minor
    Found in serviceform/serviceform/admin.py - About 55 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 contact_details has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def contact_details(request: HttpRequest, participant: models.Participant) -> HttpResponse:
        if participant and participant.status == models.Participant.STATUS_FINISHED:
            return HttpResponseRedirect(reverse('submitted'))
    
        form = forms.ContactForm(instance=participant, user=request.user)
    Severity: Minor
    Found in serviceform/serviceform/views/participation_views.py - About 55 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 invite_user has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def invite_user(self, email: str, old_participants: bool=False) -> InviteUserResponse:
            """
                Create new participations to current form version and send invites
    
            :return: int (one of InviteUserResponse constants)
    Severity: Minor
    Found in serviceform/serviceform/models/serviceform.py - About 55 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

        models.Participant.objects.filter(last_modified__lt=timezone.now() - timedelta(days=1),
                                          status=models.Participant.STATUS_ONGOING).delete()
    Severity: Minor
    Found in serviceform/serviceform/tasks.py and 1 other location - About 50 mins to fix
    serviceform/serviceform/tasks.py on lines 41..43

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

    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

        for p in models.Participant.objects.filter(
                last_modified__lt=timezone.now() - timedelta(days=1),
                status=models.Participant.STATUS_UPDATING):
    Severity: Minor
    Found in serviceform/serviceform/tasks.py and 1 other location - About 50 mins to fix
    serviceform/serviceform/tasks.py on lines 35..36

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

    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 deeply nested control flow statements.
    Open

                        if all_responsibles:
                            choice._responsibles.update(set(activity.responsibles.all()) |
                                                        set(cat1.responsibles.all()) |
                                                        set(cat2.responsibles.all()))
    
    
    Severity: Major
    Found in serviceform/serviceform/utils.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if not choice.skip_numbering:
                              choice_counter += 1
                          choice._counter = choice_counter
      Severity: Major
      Found in serviceform/serviceform/utils.py - About 45 mins to fix

        Function make has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def make(cls, name: str, form: 'ServiceForm', content: str, subject: str):
        Severity: Minor
        Found in serviceform/serviceform/models/email.py - About 35 mins to fix

          Function serviceform has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def serviceform(function=None, check_form_permission=False, init_counters=False,
          Severity: Minor
          Found in serviceform/serviceform/views/decorators.py - About 35 mins to fix

            Function save_model has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def save_model(self, request: HttpRequest, obj: models.ServiceForm, form, change: bool):
            Severity: Minor
            Found in serviceform/serviceform/admin.py - About 35 mins to fix

              Function __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def __init__(self, request: HttpRequest, participant: models.Participant,
              Severity: Minor
              Found in serviceform/serviceform/forms.py - About 35 mins to fix

                Function save_related has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def save_related(self, request: HttpRequest, form, formsets, change: bool):
                Severity: Minor
                Found in serviceform/serviceform/admin.py - About 35 mins to fix

                  Function make has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def make(cls, method: Callable, *args, scheduled_time: 'datetime'=None, **kwargs):
                  Severity: Minor
                  Found in serviceform/tasks/models.py - About 35 mins to fix
                    Severity
                    Category
                    Status
                    Source
                    Language