Noosfero/noosfero

View on GitHub
app/helpers/application_helper.rb

Summary

Maintainability
F
5 days
Test Coverage

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

module ApplicationHelper
  include PermissionNameHelper

  include UrlHelper

Severity: Major
Found in app/helpers/application_helper.rb - About 2 days to fix

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

      def display_category_item(block, categories, root = true)
        categories.map do |category|
          category_path = { controller: "search", action: "category_index", category_path: category.explode_path }
          if category.display_in_menu?
            content_tag(:li) do
    Severity: Minor
    Found in app/helpers/application_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 page_title has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      def page_title
        CGI.escapeHTML(
          (@page ? @page.title + " - " : "") +
          (@topic ? @topic.title + " - " : "") +
          (@section ? @section.title + " - " : "") +
    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 optional_field has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      def optional_field(profile, name, field_html = nil, only_required = false, &block)
        result = ""
    
        is_required = false
        if profile.required_fields.include?(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 report_depending_component has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      def report_depending_component(profile, type, content, url, text, klass, already_reported_message, report_profile_message)
        if type == :button
          if user.already_reported?(profile)
            button(:alert, text, url, class: klass + " disabled", disabled: true, title: already_reported_message)
          else
    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 radio_group has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def radio_group(object_name, method, values, options = {})
          line_size = options[:size] || 0
          line_item = 0
          html = "\n"
          values.each { |val, h_val|
    Severity: Minor
    Found in app/helpers/application_helper.rb - About 1 hr to fix

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

        def optional_field(profile, name, field_html = nil, only_required = false, &block)
          result = ""
      
          is_required = false
          if profile.required_fields.include?(name)
      Severity: Minor
      Found in app/helpers/application_helper.rb - About 1 hr to fix

        Method report_depending_component has 8 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def report_depending_component(profile, type, content, url, text, klass, already_reported_message, report_profile_message)
        Severity: Major
        Found in app/helpers/application_helper.rb - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

              if controller.action_name == "signup" || controller.action_name == "new_community" || (controller.controller_name == "enterprise_registration" && controller.action_name == "index") || (controller.controller_name == "home" && controller.action_name == "index" && user.nil?)
                if profile.signup_fields.include?(name)
                  result = field_html
                end
              else
          Severity: Major
          Found in app/helpers/application_helper.rb - About 1 hr to fix

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

              def help(content = nil, link_name = nil, options = {}, &block)
                link_name ||= font_awesome(:help, _("Help"))
            
                @help_message_id ||= 1
                help_id = "help_message_#{@help_message_id}"
            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 limited_text_area has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              def limited_text_area(object_name, method, limit, text_area_id, options = {})
            Severity: Minor
            Found in app/helpers/application_helper.rb - About 35 mins to fix

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

                def expirable_content_reference(content, action, text, url, options = {})
              Severity: Minor
              Found in app/helpers/application_helper.rb - About 35 mins to fix

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

                  def expirable_comment_link(content, action, text, url, options = {})
                Severity: Minor
                Found in app/helpers/application_helper.rb - About 35 mins to fix

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

                    def optional_field(profile, name, field_html = nil, only_required = false, &block)
                  Severity: Minor
                  Found in app/helpers/application_helper.rb - About 35 mins to fix

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

                      def file_field_or_thumbnail(label, image, for_attr, type = "default", removable = true)
                    Severity: Minor
                    Found in app/helpers/application_helper.rb - About 35 mins to fix

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

                        def expirable_button(content, action, text, url, options = {})
                      Severity: Minor
                      Found in app/helpers/application_helper.rb - About 35 mins to fix

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

                            def radio_group(object_name, method, values, options = {})
                              line_size = options[:size] || 0
                              line_item = 0
                              html = "\n"
                              values.each { |val, h_val|
                        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 theme_favicon has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def theme_favicon
                            return "/designs/themes/" + current_theme + "/favicon.ico" if profile.nil? || profile.theme.nil?
                        
                            if File.exists?(File.join(Rails.root, "public", theme_path, "favicon.ico"))
                              "/designs/themes/" + profile.theme + "/favicon.ico"
                        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 display_source_info has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def display_source_info(page)
                            if !page.source.blank?
                              source_url = link_to(page.source_name.blank? ? page.source : page.source_name, page.source)
                            elsif page.reference_article
                              source_url = link_to(page.reference_article.profile.name, page.reference_article.url)
                        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 theme_opt_menu_search has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def theme_opt_menu_search
                            opt = theme_option(:menu_search)
                            if    opt == "none"
                              ""
                            elsif opt == "simple_search"
                        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

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

                          def display_short_format(article, options = {})
                            options[:comments_link] ||= true
                            options[:read_more_link] ||= true
                            lead_links = (options[:comments_link] ? link_to_comments(article) : "") + (options[:read_more_link] ? reference_to_article(_("Read more"), article) : "")
                            html = 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

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

                          def task_information(task, params = {})
                            values = {}
                            values.merge!(task.information[:variables]) if task.information[:variables]
                            values.merge!(requestor: link_to(task.requestor.name, task.requestor.url)) if task.requestor
                            if (task.target && task.target.respond_to?(:url))
                        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

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

                          def profile_suggestion_tag_connections(suggestion)
                            tags = suggestion.tag_connections.first(4).map do |tag|
                              tag.name + ", "
                            end
                            last_tag = tags.pop
                        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

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

                          def current_editor(mode = "")
                            editor = @article.editor || Article::Editor::TINY_MCE unless @article.nil?
                            editor ||= (current_person.nil? || current_person.editor.nil?) ? Article::Editor::TINY_MCE : current_person.editor
                            editor += "_" + mode unless mode.blank?
                            editor
                        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

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

                          def search_community_options
                            host = environment.default_hostname
                            [
                              (link_to s_("communities|More recent"), controller: "search", action: "communities", order: "more_recent"),
                              (link_to s_("communities|More active"), controller: "search", action: "communities", order: "more_active"),
                        Severity: Minor
                        Found in app/helpers/application_helper.rb and 1 other location - About 35 mins to fix
                        app/helpers/application_helper.rb on lines 847..853

                        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

                          def search_people_options
                            host = environment.default_hostname
                            [
                              (link_to s_("people|More recent"), controller: "search", action: "people", order: "more_recent"),
                              (link_to s_("people|More active"), controller: "search", action: "people", order: "more_active"),
                        Severity: Minor
                        Found in app/helpers/application_helper.rb and 1 other location - About 35 mins to fix
                        app/helpers/application_helper.rb on lines 856..862

                        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

                              item[:html_options] ||= {}
                              item[:html_options][:title] ||= item[:title]
                              title = font_awesome(item[:icon], item[:title])
                              actions << link_to(title, item[:url], item[:html_options])
                        Severity: Minor
                        Found in app/helpers/application_helper.rb and 1 other location - About 30 mins to fix
                        app/helpers/article_helper.rb on lines 262..265

                        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