theforeman/foreman

View on GitHub
app/helpers/form_helper.rb

Summary

Maintainability
D
2 days
Test Coverage

File form_helper.rb has 366 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module FormHelper
  def text_f(f, attr, options = {})
    field(f, attr, options) do
      addClass options, "form-control"
      options[:focus_on_load] = true if options[:focus_on_load].nil? && attr.to_s == 'name'
Severity: Minor
Found in app/helpers/form_helper.rb - About 4 hrs to fix

    Method select_f has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

      def select_f(f, attr, array, id, method, select_options = {}, html_options = {})
        array = array.to_a.dup
        disable_button = select_options.delete(:disable_button)
        include_blank = select_options.delete(:include_blank)
        disable_button_enabled = select_options.delete(:disable_button_enabled)
    Severity: Minor
    Found in app/helpers/form_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 field has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

      def field(f, attr, options = {})
        table_field = options.delete(:table_field)
        error       = options.delete(:error) || get_attr_error(f, attr)
        help_inline = help_inline(options.delete(:help_inline), error)
        help_inline += options[:help_inline_permanent] unless options[:help_inline_permanent].nil?
    Severity: Minor
    Found in app/helpers/form_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 select_f has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def select_f(f, attr, array, id, method, select_options = {}, html_options = {})
        array = array.to_a.dup
        disable_button = select_options.delete(:disable_button)
        include_blank = select_options.delete(:include_blank)
        disable_button_enabled = select_options.delete(:disable_button_enabled)
    Severity: Minor
    Found in app/helpers/form_helper.rb - About 1 hr to fix

      Method field has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def field(f, attr, options = {})
          table_field = options.delete(:table_field)
          error       = options.delete(:error) || get_attr_error(f, attr)
          help_inline = help_inline(options.delete(:help_inline), error)
          help_inline += options[:help_inline_permanent] unless options[:help_inline_permanent].nil?
      Severity: Minor
      Found in app/helpers/form_helper.rb - About 1 hr to fix

        Method multiple_selects has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def multiple_selects(f, attr, associations, selected_ids, options = {}, html_options = {})
            options[:size] = "col-md-10"
            case attr
              when :organizations
                klass = Organization
        Severity: Minor
        Found in app/helpers/form_helper.rb - About 1 hr to fix

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

            def password_f(f, attr, options = {})
              unset_button = options.delete(:unset)
              value = f.object[attr] if options.delete(:keep_value)
              password_field_tag(:fakepassword, value, :style => 'display: none', :autocomplete => 'new-password-fake') +
                  field(f, attr, options) do
          Severity: Minor
          Found in app/helpers/form_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 multiple_selects has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

            def multiple_selects(f, attr, associations, selected_ids, options = {}, html_options = {})
              options[:size] = "col-md-10"
              case attr
                when :organizations
                  klass = Organization
          Severity: Minor
          Found in app/helpers/form_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 select_f has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

            def select_f(f, attr, array, id, method, select_options = {}, html_options = {})
          Severity: Major
          Found in app/helpers/form_helper.rb - About 50 mins to fix

            Method multiple_selects has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              def multiple_selects(f, attr, associations, selected_ids, options = {}, html_options = {})
            Severity: Minor
            Found in app/helpers/form_helper.rb - About 45 mins to fix

              Method multiple_checkboxes has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                def multiple_checkboxes(f, attr, klass, associations, options = {}, html_options = {})
              Severity: Minor
              Found in app/helpers/form_helper.rb - About 45 mins to fix

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

                  def submit_or_cancel(f, overwrite = false, args = { })
                    args[:cancel_path] ||= resource_path(controller_name)
                    cancel_btn = args[:react_cancel_button] ? react_cancel_button(args) : link_to(_("Cancel"), args[:cancel_path], :class => "btn btn-default")
                    content_tag(:div, :class => "clearfix") do
                      content_tag(:div, :class => "form-actions") do
                Severity: Minor
                Found in app/helpers/form_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 form_select_f has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                  def form_select_f(f, attr, array, select_options = {}, html_options = {})
                Severity: Minor
                Found in app/helpers/form_helper.rb - About 35 mins to fix

                  Method time_zone_select_f has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                    def time_zone_select_f(f, attr, default_timezone, select_options = {}, html_options = {})
                  Severity: Minor
                  Found in app/helpers/form_helper.rb - About 35 mins to fix

                    Method checkbox_f has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                      def checkbox_f(f, attr, options = {}, checked_value = "1", unchecked_value = "0")
                    Severity: Minor
                    Found in app/helpers/form_helper.rb - About 35 mins to fix

                      Method link_to_add_fields has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                        def link_to_add_fields(name, f, association, partial = nil, options = {})
                      Severity: Minor
                      Found in app/helpers/form_helper.rb - About 35 mins to fix

                        Method orderable_select_f has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                          def orderable_select_f(f, attr, choices, select_options = {}, html_options = {})
                        Severity: Minor
                        Found in app/helpers/form_helper.rb - About 35 mins to fix

                          Method selectable_f has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                            def selectable_f(f, attr, array, select_options = {}, html_options = {})
                          Severity: Minor
                          Found in app/helpers/form_helper.rb - About 35 mins to fix

                            Method selectable_f_inline has 5 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                              def selectable_f_inline(f, attr, array, select_options = {}, html_options = {})
                            Severity: Minor
                            Found in app/helpers/form_helper.rb - About 35 mins to fix

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

                                def add_label(options, f, attr)
                                  return ''.html_safe if options[:label] == :none
                              
                                  label_size = options.delete(:label_size) || "col-md-2"
                                  required_mark = check_required(options, f, attr)
                              Severity: Minor
                              Found in app/helpers/form_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