SysMO-DB/seek

View on GitHub
app/helpers/application_helper.rb

Summary

Maintainability
F
4 days
Test Coverage

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

require 'savage_beast/application_helper'
require 'app_version'

module ApplicationHelper  
  include SavageBeast::ApplicationHelper
Severity: Major
Found in app/helpers/application_helper.rb - About 1 day to fix

    Method text_or_not_specified has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

      def text_or_not_specified text, options = {}
        text=text.to_s if text.kind_of?(Numeric)
        if text.nil? or text.chomp.empty?
          not_specified_text||=options[:none_text]
          not_specified_text||="No description specified" if options[:description]==true
    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 authorized_list has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

      def authorized_list all_items, attribute, sort=true, max_length=75, count_hidden_items=false
        items = all_items.select &:can_view?
        if Seek::Config.is_virtualliver
          title_only_items = (all_items - items).select &:title_is_public?
        else
    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 set_parameters_for_sharing_form has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      def set_parameters_for_sharing_form object=nil
        object ||= eval "@#{controller_name.singularize}"
        policy = nil
        policy_type = ""
    
    
    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 date_as_string has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      def date_as_string date,show_time_of_day=false,year_only_1st_jan=false
        #for publications, if it is the first of jan, then it can be assumed it is just the year (unlikely have a publication on New Years Day)
        if (year_only_1st_jan && !date.blank? && date.month==1 && date.day==1)
          str=date.year.to_s
        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 windowed_pagination_links has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      def windowed_pagination_links(pagingEnum, options)
        link_to_current_page = options[:link_to_current_page]
        always_show_anchors = options[:always_show_anchors]
        padding = options[:window_size]
    
    
    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 set_parameters_for_sharing_form has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def set_parameters_for_sharing_form object=nil
        object ||= eval "@#{controller_name.singularize}"
        policy = nil
        policy_type = ""
    
    
    Severity: Minor
    Found in app/helpers/application_helper.rb - About 1 hr to fix

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

        def truncate_without_splitting_words(text, length=50)
          truncated_result = ""
          remaining_length = length
          stop = false
          truncated = false
      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 contributor has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        def contributor(contributor, avatar=false, size=100, you_text=false)
          return jerm_harvester_name unless contributor
          
          if contributor.class.name == "User"
            # this string will output " (you) " for current user next to the display name, when invoked with 'you_text == true'
      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 authorized_list has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def authorized_list all_items, attribute, sort=true, max_length=75, count_hidden_items=false
          items = all_items.select &:can_view?
          if Seek::Config.is_virtualliver
            title_only_items = (all_items - items).select &:title_is_public?
          else
      Severity: Minor
      Found in app/helpers/application_helper.rb - About 1 hr to fix

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

          def internationalized_resource_name resource_type,pluralize=true
            resource_type = resource_type.singularize
            if resource_type == "Speciman"
              result = t('biosamples.sample_parent_term')
            elsif resource_type == "Assay"
        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 resource_tab_item_name has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def resource_tab_item_name resource_type,pluralize=true
            resource_type = resource_type.singularize
            if resource_type == "Speciman"
              result = t('biosamples.sample_parent_term')
            elsif resource_type == "Assay"
        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 list_item_with_icon has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def list_item_with_icon(icon_type, item, caption, truncate_to, custom_tooltip=nil, size=nil)
            list_item = "<li>"
            if icon_type.downcase == "flag"
              list_item += flag_icon(item.country)
            elsif icon_type == "data_file" || icon_type == "sop"
        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 list_item_with_icon has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def list_item_with_icon(icon_type, item, caption, truncate_to, custom_tooltip=nil, size=nil)
        Severity: Minor
        Found in app/helpers/application_helper.rb - About 45 mins to fix

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

            def authorized_list all_items, attribute, sort=true, max_length=75, count_hidden_items=false
          Severity: Minor
          Found in app/helpers/application_helper.rb - About 35 mins to fix

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

              def classify_for_tabs result_collection
                results={}
            
                result_collection.each do |res|
                  tab = res.respond_to?(:tab) ? res.tab : res.class.name
            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 describe_visibility has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def describe_visibility(model)
                text = '<strong>Visibility:</strong> '
            
                if model.policy.sharing_scope == 0
                  css_class = 'private'
            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 hidden_item_contributor_links has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def hidden_item_contributor_links hidden_items
                contributor_links = []
                hidden_items = hidden_items.select { |hi| !hi.contributing_user.try(:person).nil? }
                hidden_items.sort! { |a, b| a.contributing_user.person.name <=> b.contributing_user.person.name }
                hidden_items.each do |hi|
            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 tab_definition has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def tab_definition(options={})
                options[:gap_before] ||= false
                options[:title] ||= options[:controllers].first.capitalize
                options[:path] ||= eval "#{options[:controllers].first}_path"
            
            
            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

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

              def classify_for_tabs result_collection
                results={}
            
                result_collection.each do |res|
                  tab = res.respond_to?(:tab) ? res.tab : res.class.name
            Severity: Minor
            Found in app/helpers/application_helper.rb and 1 other location - About 1 hr to fix
            lib/seek/faceted_browsing.rb on lines 82..91

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

            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 seek_javascript_tags main='application'
                js = (Seek::Config.javascript_prepended || "").split(",")
                js << main
                js = js | (Seek::Config.javascript_appended || "").split(",")
                js.empty? ? "" : javascript_include_tag(*js)
            Severity: Minor
            Found in app/helpers/application_helper.rb and 1 other location - About 30 mins to fix
            app/helpers/application_helper.rb on lines 17..22

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

            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 seek_stylesheet_tags main='application'
                css = (Seek::Config.css_prepended || "").split(",")
                css << main
                css = css | (Seek::Config.css_appended || "").split(",")
                css.empty? ? "" : stylesheet_link_tag(*css)
            Severity: Minor
            Found in app/helpers/application_helper.rb and 1 other location - About 30 mins to fix
            app/helpers/application_helper.rb on lines 24..29

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

            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 favourite_group_popup_link_action_new resource_type=nil
                return link_to_remote_redbox("Create new #{t('favourite_group')}",
                  { :url => main_app.new_favourite_group_url,
                    :failure => "alert('Sorry, an error has occurred.'); RedBox.close();",
                    :with => "'resource_type=' + '#{resource_type}'" },
            Severity: Minor
            Found in app/helpers/application_helper.rb and 1 other location - About 15 mins to fix
            app/helpers/application_helper.rb on lines 377..384

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

            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 favourite_group_popup_link_action_edit resource_type=nil
                return link_to_remote_redbox("Edit selected #{t('favourite_group')}",
                  { :url => main_app.edit_favourite_group_url,
                    :failure => "alert('Sorry, an error has occurred.'); RedBox.close();",
                    :with => "'resource_type=' + '#{resource_type}' + '&id=' + selectedFavouriteGroup()" },
            Severity: Minor
            Found in app/helpers/application_helper.rb and 1 other location - About 15 mins to fix
            app/helpers/application_helper.rb on lines 364..371

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

            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