otwcode/otwarchive

View on GitHub
app/helpers/application_helper.rb

Summary

Maintainability
F
3 days
Test Coverage

File application_helper.rb has 457 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module ApplicationHelper
  include HtmlCleaner

  # TODO: Official recommendation from Rails indicates we should switch to
  # unobtrusive JavaScript instead of using anything like `link_to_function`
Severity: Minor
Found in app/helpers/application_helper.rb - About 7 hrs to fix

    Method sort_link has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

      def sort_link(title, column=nil, options = {})
        condition = options[:unless] if options.has_key?(:unless)
    
        unless column.nil?
          current_column = (params[:sort_column] == column.to_s) || params[:sort_column].blank? && options[:sort_default]
    Severity: Minor
    Found in app/helpers/application_helper.rb - About 5 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 checkbox_section has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

      def checkbox_section(form, attribute, choices, options = {})
        options = {
          checked_method: nil,
          name_method: "name",
          name_helper_method: nil, # alternative: pass a helper method that gets passed the choice
    Severity: Minor
    Found in app/helpers/application_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 checkbox_section has 52 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def checkbox_section(form, attribute, choices, options = {})
        options = {
          checked_method: nil,
          name_method: "name",
          name_helper_method: nil, # alternative: pass a helper method that gets passed the choice
    Severity: Major
    Found in app/helpers/application_helper.rb - About 2 hrs to fix

      Method byline_text has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        def byline_text(creation, only_path, text_only = false)
          if creation.respond_to?(:author)
            creation.author
          else
            pseuds = @preview_mode ? creation.pseuds_after_saving : creation.pseuds.to_a
      Severity: Minor
      Found in app/helpers/application_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 field_name has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        def field_name(form_or_object_name, attribute, *_method_names, multiple: false, index: nil)
          object_name = if form_or_object_name.respond_to?(:object_name)
                          form_or_object_name.object_name
                        else
                          form_or_object_name
      Severity: Minor
      Found in app/helpers/application_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 permit_all_except has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

        def permit_all_except(params, blocked_keys)
          if params.respond_to?(:each_pair)
            {}.tap do |result|
              params.each_pair do |key, value|
                key = key.to_sym
      Severity: Minor
      Found in app/helpers/application_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 checkbox_section_toggle has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def checkbox_section_toggle(checkboxes_id, checkboxes_size, options = {})
          toggle_show = content_tag(:a, ts("Expand %{checkboxes_size} Checkboxes", checkboxes_size: checkboxes_size),
                                    class: "toggle #{checkboxes_id}_show") + "\n".html_safe
      
          toggle_hide = content_tag(:a, ts("Collapse Checkboxes"),
      Severity: Minor
      Found in app/helpers/application_helper.rb - About 1 hr to fix

        Method classes_for_main has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          def classes_for_main
            class_names = controller.controller_name + '-' + controller.action_name
        
            show_sidebar = ((@user || @admin_posts || @collection || show_wrangling_dashboard) && !@hide_dashboard)
            class_names += " dashboard" if show_sidebar
        Severity: Minor
        Found in app/helpers/application_helper.rb - 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

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

          def span_if_current(link_to_default_text, path, condition=nil, title_attribute_default_text=nil)
            is_current = condition.nil? ? current_page?(path) : condition
            span_tag = title_attribute_default_text.nil? ? "<span class=\"current\">#{link_to_default_text}</span>" : "<span class=\"current\" title=\"#{title_attribute_default_text}\">#{link_to_default_text}</span>"
            link_code = title_attribute_default_text.nil? ? link_to(link_to_default_text, path) : link_to(link_to_default_text, path, title: "#{title_attribute_default_text}")
            is_current ? span_tag.html_safe : link_code
        Severity: Minor
        Found in app/helpers/application_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 checkbox_section_css_class has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def checkbox_section_css_class(size, concise=false)
            css_class = "options index group"
        
            if concise
              css_class += " concise lots" if size > ArchiveConfig.OPTIONS_TO_SHOW
        Severity: Minor
        Found in app/helpers/application_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 link_to_add_section has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def link_to_add_section(linktext, form, nested_model_name, partial_to_render, locals = {})
        Severity: Minor
        Found in app/helpers/application_helper.rb - About 35 mins to fix

          Method text_byline has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def text_byline(creation, options={})
              if creation.respond_to?(:anonymous?) && creation.anonymous?
                anon_byline = ts("Anonymous")
                if (logged_in_as_admin? || is_author_of?(creation)) && options[:visibility] != 'public'
                  anon_byline += " [#{non_anonymous_byline(creation)}]".html_safe
          Severity: Minor
          Found in app/helpers/application_helper.rb - About 35 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 time_in_zone has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def time_in_zone(time, zone = nil, user = User.current_user)
              return ts("(no time specified)") if time.blank?
          
              zone ||= (user&.is_a?(User) && user.preference.time_zone) ? user.preference.time_zone : Time.zone.name
              time_in_zone = time.in_time_zone(zone)
          Severity: Minor
          Found in app/helpers/application_helper.rb - About 35 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 flash_div has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def flash_div *keys
              keys.collect { |key|
                if flash[key]
                  if flash[key].is_a?(Array)
                    content_tag(:div,
          Severity: Minor
          Found in app/helpers/application_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

          There are no issues that match your filters.

          Category
          Status