JumpstartLab/tracks

View on GitHub
app/helpers/todos_helper.rb

Summary

Maintainability
F
5 days
Test Coverage

Method show_empty_message_in_source_container has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
Open

  def show_empty_message_in_source_container
    container_id = ""
    source_view do |page|
      page.project  {
        container_id = "p#{@original_item_project_id}empty-nd" if @remaining_in_context == 0
Severity: Minor
Found in app/helpers/todos_helper.rb - 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 todos_helper.rb has 410 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module TodosHelper

  def remote_star_icon(todo=@todo)
    link_to( image_tag_for_star(todo),
      toggle_star_todo_path(todo),
Severity: Minor
Found in app/helpers/todos_helper.rb - About 5 hrs to fix

    Method project_and_context_links has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

      def project_and_context_links(todo, parent_container_type, opts = {})
        str = ''
        if todo.completed?
          str += todo.context.name unless opts[:suppress_context]
          should_suppress_project = opts[:suppress_project] || todo.project.nil?
    Severity: Minor
    Found in app/helpers/todos_helper.rb - About 2 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

    Consider simplifying this complex logical expression.
    Open

        return (@remaining_in_context == 0 && (@todo_hidden_state_changed && @todo.hidden?)) ||
          (@remaining_in_context == 0 && @todo_was_deferred_from_active_state) ||
          (@remaining_in_context == 0 && @tag_was_removed) ||
          (@remaining_in_context == 0 && @todo.completed? && !(@original_item_was_deferred || @original_item_was_hidden)) if source_view_is(:tag)
    Severity: Critical
    Found in app/helpers/todos_helper.rb - About 2 hrs to fix

      Method empty_container_msg_div_id has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

        def empty_container_msg_div_id(todo = @todo || @successor)
          raise Exception.new, "no @todo or @successor set" if !todo
      
          source_view do |page|
            page.project  {
      Severity: Minor
      Found in app/helpers/todos_helper.rb - About 2 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

      Method empty_container_msg_div_id has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def empty_container_msg_div_id(todo = @todo || @successor)
          raise Exception.new, "no @todo or @successor set" if !todo
      
          source_view do |page|
            page.project  {
      Severity: Minor
      Found in app/helpers/todos_helper.rb - About 1 hr to fix

        Method should_show_new_item has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          def should_show_new_item
            source_view do |page|
              page.todo { return !@todo.hidden? }
              page.deferred { return @todo.deferred? || @todo.pending? }
              page.context {
        Severity: Minor
        Found in app/helpers/todos_helper.rb - 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

        Method update_needs_to_hide_context has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          def update_needs_to_hide_context
            return (@remaining_in_context == 0 && (@todo_hidden_state_changed && @todo.hidden?)) ||
              (@remaining_in_context == 0 && @todo_was_deferred_from_active_state) ||
              (@remaining_in_context == 0 && @tag_was_removed) ||
              (@remaining_in_context == 0 && @todo.completed? && !(@original_item_was_deferred || @original_item_was_hidden)) if source_view_is(:tag)
        Severity: Minor
        Found in app/helpers/todos_helper.rb - 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

        Method item_container_id has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def item_container_id (todo)
            return "hiddenitems"              if source_view_is(:tag) && todo.hidden?
            return "c#{todo.context_id}items" if source_view_is :deferred
            return @new_due_id                if source_view_is :calendar
            return "tickleritems"             if !source_view_is(:todo) && (todo.deferred? || todo.pending?)
        Severity: Minor
        Found in app/helpers/todos_helper.rb - 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

        Method feed_content_for_todo has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def feed_content_for_todo(todo)
            item_notes = todo.notes ? todo.rendered_notes : ''
            due = todo.due ? content_tag(:div, t('todos.feeds.due', :date => format_date(todo.due))) : ''
            done = todo.completed? ? content_tag(:div, t('todos.feeds.completed', :date => format_date(todo.completed_at))) : ''
            context_link = link_to(context_url(todo.context), todo.context.name)
        Severity: Minor
        Found in app/helpers/todos_helper.rb - 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

        Consider simplifying this complex logical expression.
        Open

                return "tickler-empty-nd" if
                  @todo_was_deferred_from_active_state ||
                  @todo_was_blocked_from_active_state ||
                  @todo_was_destroyed_from_deferred_state ||
                  @todo_was_created_deferred ||
        Severity: Major
        Found in app/helpers/todos_helper.rb - About 40 mins to fix

          Consider simplifying this complex logical expression.
          Open

                  container_id = "hidden-empty-nd" if (@remaining_hidden_count == 0 && !@todo.hidden? && @todo_hidden_state_changed) ||
                    (@remaining_hidden_count == 0 && @todo.completed? && @original_item_was_hidden)
          Severity: Major
          Found in app/helpers/todos_helper.rb - About 40 mins to fix

            Consider simplifying this complex logical expression.
            Open

                    return "tickler-empty-nd" if
                      @todo_was_deferred_from_active_state ||
                      @todo_was_blocked_from_active_state ||
                      @todo_was_destroyed_from_deferred_state ||
                      @todo_was_created_deferred ||
            Severity: Major
            Found in app/helpers/todos_helper.rb - About 40 mins to fix

              Consider simplifying this complex logical expression.
              Open

                      return "tickler-empty-nd" if
                        @todo_was_deferred_from_active_state ||
                        @todo_was_blocked_from_active_state ||
                        @todo_was_destroyed_from_deferred_state ||
                        @todo_was_created_deferred ||
              Severity: Major
              Found in app/helpers/todos_helper.rb - About 40 mins to fix

                Consider simplifying this complex logical expression.
                Open

                        return "tickler-empty-nd" if
                          @todo_was_deferred_from_active_state ||
                          @todo_was_blocked_from_active_state ||
                          @todo_was_destroyed_from_deferred_state ||
                          @todo_was_created_deferred ||
                Severity: Major
                Found in app/helpers/todos_helper.rb - About 40 mins to fix

                  Consider simplifying this complex logical expression.
                  Open

                          container_id = "tickler-empty-nd" if (todo_was_removed_from_deferred_or_blocked_container && @remaining_deferred_or_pending_count == 0) ||
                            (@original_item_was_deferred && @remaining_deferred_or_pending_count == 0 && (@todo.completed? || @tag_was_removed))
                  Severity: Major
                  Found in app/helpers/todos_helper.rb - About 40 mins to fix

                    Avoid too many return statements within this method.
                    Open

                          page.todo     { return @context_changed || @todo.hidden? || @todo.deferred? || @todo.pending?}
                    Severity: Major
                    Found in app/helpers/todos_helper.rb - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return "c#{todo.context_id}empty-nd"
                      Severity: Major
                      Found in app/helpers/todos_helper.rb - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                return (@todo.active? && @todo.project && @todo.project.id == @default_project.id) ||
                                  (@todo.project.hidden? && @todo.project_hidden?) ||
                                  ( @todo.deferred? && (@todo.project.id == @default_project.id) ) ||
                                  @todo.pending?
                        Severity: Major
                        Found in app/helpers/todos_helper.rb - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return "c#{todo.context_id}empty-nd"
                          Severity: Major
                          Found in app/helpers/todos_helper.rb - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                return false
                            Severity: Major
                            Found in app/helpers/todos_helper.rb - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                      return "empty_#{@new_due_id}"
                              Severity: Major
                              Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                      page.stats    { return @todo.completed? }
                                Severity: Major
                                Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          return "tickler-empty-nd" if
                                  Severity: Major
                                  Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                        return "c#{todo.context_id}empty-nd"
                                    Severity: Major
                                    Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                          return 'context'
                                      Severity: Major
                                      Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                              page.tag      { return !update_needs_to_remove_todo_from_container && !@tag_was_removed }
                                        Severity: Major
                                        Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                page.tag      { return update_needs_to_remove_todo_from_container && !@tag_was_removed}
                                          Severity: Major
                                          Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                    return "tickler-empty-nd" if
                                            Severity: Major
                                            Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                    page.tag      { return (@context_changed && !@todo.hidden?) || @tag_was_removed || @todo_hidden_state_changed || @todo_deferred_state_changed }
                                              Severity: Major
                                              Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                    return "c#{todo.context_id}items"
                                                Severity: Major
                                                Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                      return false
                                                  Severity: Major
                                                  Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                                    Avoid too many return statements within this method.
                                                    Open

                                                          page.search   { return false }
                                                    Severity: Major
                                                    Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                                      Avoid too many return statements within this method.
                                                      Open

                                                            page.todo     { return !update_needs_to_remove_todo_from_container }
                                                      Severity: Major
                                                      Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                                        Avoid too many return statements within this method.
                                                        Open

                                                            return false
                                                        Severity: Major
                                                        Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                                          Avoid too many return statements within this method.
                                                          Open

                                                                page.stats    { return false }
                                                          Severity: Major
                                                          Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                                            Avoid too many return statements within this method.
                                                            Open

                                                                  page.todo     { return @context_changed && !(@todo.deferred? || @todo.pending? || @todo.hidden?) }
                                                            Severity: Major
                                                            Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                                              Avoid too many return statements within this method.
                                                              Open

                                                                    page.search   { return true }
                                                              Severity: Major
                                                              Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                                                Avoid too many return statements within this method.
                                                                Open

                                                                    return "completed_containeritems" if todo.completed?
                                                                Severity: Major
                                                                Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                                                  Avoid too many return statements within this method.
                                                                  Open

                                                                        page.stats    { return !@todo.completed? }
                                                                  Severity: Major
                                                                  Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                                                    Avoid too many return statements within this method.
                                                                    Open

                                                                        return false
                                                                    Severity: Major
                                                                    Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                                                      Avoid too many return statements within this method.
                                                                      Open

                                                                          return "p#{todo.project_id}items" if source_view_is :project
                                                                      Severity: Major
                                                                      Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                                                        Avoid too many return statements within this method.
                                                                        Open

                                                                              return ""
                                                                        Severity: Major
                                                                        Found in app/helpers/todos_helper.rb - About 30 mins to fix

                                                                          Method remote_defer_menu_item has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                          Open

                                                                            def remote_defer_menu_item(days, todo)
                                                                              url = {:controller => 'todos', :action => 'defer', :id => todo.id, :days => days,
                                                                                :_source_view => (@source_view.underscore.gsub(/\s+/,'_') rescue "")}
                                                                              url[:_tag_name] = @tag_name if @source_view == 'tag'
                                                                          
                                                                          
                                                                          Severity: Minor
                                                                          Found in app/helpers/todos_helper.rb - 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

                                                                          Method staleness_class has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                          Open

                                                                            def staleness_class(item)
                                                                              if item.due || item.completed?
                                                                                return ""
                                                                              elsif item.created_at < current_user.time - (prefs.staleness_starts * 3).days
                                                                                return " stale_l3"
                                                                          Severity: Minor
                                                                          Found in app/helpers/todos_helper.rb - 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

                                                                                page.context  {
                                                                                  container_id = "c#{@original_item_context_id}empty-nd" if @remaining_in_context == 0
                                                                                  container_id = "tickler-empty-nd" if todo_was_removed_from_deferred_or_blocked_container && @remaining_deferred_or_pending_count == 0
                                                                                  container_id = "empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
                                                                                }
                                                                          Severity: Minor
                                                                          Found in app/helpers/todos_helper.rb and 1 other location - About 30 mins to fix
                                                                          app/helpers/todos_helper.rb on lines 419..423

                                                                          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

                                                                                page.project  {
                                                                                  container_id = "p#{@original_item_project_id}empty-nd" if @remaining_in_context == 0
                                                                                  container_id = "tickler-empty-nd" if todo_was_removed_from_deferred_or_blocked_container && @remaining_deferred_or_pending_count == 0
                                                                                  container_id = "empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
                                                                                }
                                                                          Severity: Minor
                                                                          Found in app/helpers/todos_helper.rb and 1 other location - About 30 mins to fix
                                                                          app/helpers/todos_helper.rb on lines 433..437

                                                                          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

                                                                          There are no issues that match your filters.

                                                                          Category
                                                                          Status