redmine/redmine

View on GitHub
app/helpers/queries_helper.rb

Summary

Maintainability
F
4 days
Test Coverage

File queries_helper.rb has 451 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'redmine/export/csv'

module QueriesHelper
  include ApplicationHelper

Severity: Minor
Found in app/helpers/queries_helper.rb - About 6 hrs to fix

    Method filters_options_for_select has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

      def filters_options_for_select(query)
        ungrouped = []
        grouped = {label_string: [], label_date: [], label_time_tracking: [], label_attachment: []}
        query.available_filters.map do |field, field_options|
          if /^cf_\d+\./.match?(field)
    Severity: Minor
    Found in app/helpers/queries_helper.rb - 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

    Method retrieve_query has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

      def retrieve_query(klass=IssueQuery, use_session=true, options={})
        session_key = klass.name.underscore.to_sym
    
        if params[:query_id].present?
          scope = klass.where(:project_id => nil)
    Severity: Minor
    Found in app/helpers/queries_helper.rb - 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

    Method grouped_query_results has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

      def grouped_query_results(items, query, &block)
        result_count_by_group = query.result_count_by_group
        previous_group, first = false, true
        totals_by_group = query.totalable_columns.inject({}) do |h, column|
          h[column] = query.total_by_group_for(column)
    Severity: Minor
    Found in app/helpers/queries_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 csv_value has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

      def csv_value(column, object, value)
        case column.name
        when :attachments
          value.to_a.map {|a| a.filename}.join("\n")
        else
    Severity: Minor
    Found in app/helpers/queries_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 retrieve_query has 45 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def retrieve_query(klass=IssueQuery, use_session=true, options={})
        session_key = klass.name.underscore.to_sym
    
        if params[:query_id].present?
          scope = klass.where(:project_id => nil)
    Severity: Minor
    Found in app/helpers/queries_helper.rb - About 1 hr to fix

      Method column_value has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        def column_value(column, item, value)
          content =
            case column.name
            when :id
              link_to value, issue_path(item)
      Severity: Minor
      Found in app/helpers/queries_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 column_header has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def column_header(query, column, options={})
          if column.sortable?
            css, order = nil, column.default_order
            if column.name.to_s == query.sort_criteria.first_key
              if query.sort_criteria.first_asc?
      Severity: Minor
      Found in app/helpers/queries_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 filters_options_for_select has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def filters_options_for_select(query)
          ungrouped = []
          grouped = {label_string: [], label_date: [], label_time_tracking: [], label_attachment: []}
          query.available_filters.map do |field, field_options|
            if /^cf_\d+\./.match?(field)
      Severity: Minor
      Found in app/helpers/queries_helper.rb - About 1 hr to fix

        Method retrieve_query_from_session has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

          def retrieve_query_from_session(klass=IssueQuery)
            session_key = klass.name.underscore.to_sym
            session_data = session[session_key]
        
            if session_data
        Severity: Minor
        Found in app/helpers/queries_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 query_links has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def query_links(title, queries)
            return '' if queries.empty?
        
            # links to #index on issues/show
            url_params =
        Severity: Minor
        Found in app/helpers/queries_helper.rb - About 1 hr to fix

          Method column_value has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def column_value(column, item, value)
              content =
                case column.name
                when :id
                  link_to value, issue_path(item)
          Severity: Minor
          Found in app/helpers/queries_helper.rb - About 1 hr to fix

            Method column_header has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def column_header(query, column, options={})
                if column.sortable?
                  css, order = nil, column.default_order
                  if column.name.to_s == query.sort_criteria.first_key
                    if query.sort_criteria.first_asc?
            Severity: Minor
            Found in app/helpers/queries_helper.rb - About 1 hr to fix

              Method query_links has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                def query_links(title, queries)
                  return '' if queries.empty?
              
                  # links to #index on issues/show
                  url_params =
              Severity: Minor
              Found in app/helpers/queries_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 query_as_hidden_field_tags has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def query_as_hidden_field_tags(query)
                  tags = hidden_field_tag("set_filter", "1", :id => nil)
              
                  if query.filters.present?
                    query.filters.each do |field, filter|
              Severity: Minor
              Found in app/helpers/queries_helper.rb - About 1 hr to fix

                Method retrieve_query_from_session has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def retrieve_query_from_session(klass=IssueQuery)
                    session_key = klass.name.underscore.to_sym
                    session_data = session[session_key]
                
                    if session_data
                Severity: Minor
                Found in app/helpers/queries_helper.rb - About 1 hr to fix

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

                      query.filters.each do |field, options|
                        tags << hidden_field_tag("f[]", field, :id => nil)
                        tags << hidden_field_tag("op[#{field}]", options[:operator], :id => nil)
                        options[:values].each do |value|
                          tags << hidden_field_tag("v[#{field}][]", value, :id => nil)
                  Severity: Minor
                  Found in app/helpers/queries_helper.rb and 1 other location - About 55 mins to fix
                  app/helpers/queries_helper.rb on lines 432..436

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

                  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

                        query.filters.each do |field, filter|
                          tags << hidden_field_tag("f[]", field, :id => nil)
                          tags << hidden_field_tag("op[#{field}]", filter[:operator], :id => nil)
                          filter[:values].each do |value|
                            tags << hidden_field_tag("v[#{field}][]", value, :id => nil)
                  Severity: Minor
                  Found in app/helpers/queries_helper.rb and 1 other location - About 55 mins to fix
                  app/helpers/queries_helper.rb on lines 71..75

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

                  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