MiraitSystems/enju_trunk

View on GitHub
app/helpers/manifestations_helper.rb

Summary

Maintainability
F
3 days
Test Coverage

File manifestations_helper.rb has 411 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module ManifestationsHelper
  def resource_title(manifestation, action)
    string = LibraryGroup.site_config.display_name.localize.dup
    unless action == ('index' or 'new')
      if manifestation.try(:original_title)
Severity: Minor
Found in app/helpers/manifestations_helper.rb - About 5 hrs to fix

    Method hide_item? has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

      def hide_item?(show_all = false, item)
        unless user_signed_in? and current_user.has_role?('Librarian') and SystemConfiguration.get("manifestation.show_all")
          if @removed
            return true unless item.circulation_status.name == "Removed"
          else 
    Severity: Minor
    Found in app/helpers/manifestations_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 set_serial_number has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

      def set_serial_number(m)
        if m.serial_number_string.present? 
          m.serial_number_string = m.serial_number_string.match(/\D/) ? nil : m.serial_number_string.to_i + 1
          unless m.issue_number_string.blank?
            m.issue_number_string = m.issue_number_string.match(/\D/) ? nil : m.issue_number_string.to_i + 1
    Severity: Minor
    Found in app/helpers/manifestations_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 paginate_ncid_link has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

      def paginate_ncid_link(nacsis_cat)
        return nil unless nacsis_cat.is_a?(NacsisCat)
        links = []
        if nacsis_cat.serial?
          ids_ary = session['nacsis_cat_serial_ids']
    Severity: Minor
    Found in app/helpers/manifestations_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 volume_display has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      def volume_display(manifestation)
        return true if manifestation.edition_display_value?
        return true unless manifestation.volume_number_string.blank?
    
        unless SystemConfiguration.get("manifestation.volume_number_string_only")
    Severity: Minor
    Found in app/helpers/manifestations_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 paginate_id_link has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

      def paginate_id_link(manifestation)
        links = []
        if session[:manifestation_ids].is_a?(Array)
          current_seq = session[:manifestation_ids].index(manifestation.id)
          if current_seq
    Severity: Minor
    Found in app/helpers/manifestations_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 circulation_status_facet has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

      def circulation_status_facet(type, facet)
        string = ''
        current = false
        case type
        when 'in_process'
    Severity: Minor
    Found in app/helpers/manifestations_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 carrier_type_facet has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

      def carrier_type_facet(facet)
        string = ''
        carrier_type = CarrierType.where(:name => facet.value).select([:name, :display_name, :icon_filename]).first
        if carrier_type
          if icon = form_icon(carrier_type)
    Severity: Minor
    Found in app/helpers/manifestations_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 manifestation_page has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def manifestation_page(manifestation)
        page = ""
        if manifestation.start_page and manifestation.start_page.present? and manifestation.end_page and manifestation.end_page.present?
          if manifestation.start_page == manifestation.end_page
            page = "(#{manifestation.start_page})"
    Severity: Minor
    Found in app/helpers/manifestations_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 language_facet has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def language_facet(language, current_languages, facet)
        string = ''
        languages = current_languages.dup
        current = true if languages.include?(language.name)
        if current
    Severity: Minor
    Found in app/helpers/manifestations_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 display_work_has_languages has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

      def display_work_has_languages(manifestation)
        return nil if manifestation.nil? || manifestation.work_has_languages.blank?
        list = []
        manifestation.work_has_languages.each do |whl|
          str = ''
    Severity: Minor
    Found in app/helpers/manifestations_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

    Avoid too many return statements within this method.
    Open

              return true if item.use_restriction.name == 'Not For Loan'
    Severity: Major
    Found in app/helpers/manifestations_helper.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

          return false
      Severity: Major
      Found in app/helpers/manifestations_helper.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                    return true if item.rank == 2
        Severity: Major
        Found in app/helpers/manifestations_helper.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                    return true if item.try(:circulation_status).try(:name) == 'Removed'
          Severity: Major
          Found in app/helpers/manifestations_helper.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                      return true  if item.try(:circulation_status).try(:unsearchable)
            Severity: Major
            Found in app/helpers/manifestations_helper.rb - About 30 mins to fix

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

                def library_facet(library, current_libraries, facet)
                  string = ''
                  current = true if current_libraries.include?(library.name)
                  string << "<strong>" if current
                  string << link_to("#{library.display_name.localize} (" + facet.count.to_s + ")", url_for(params.merge(:page => nil, :library => (current_libraries << library.name).uniq.join(' '), :view => nil)))
              Severity: Major
              Found in app/helpers/manifestations_helper.rb and 4 other locations - About 1 hr to fix
              app/helpers/shelves_helper.rb on lines 15..21
              app/helpers/users_helper.rb on lines 52..58
              app/helpers/users_helper.rb on lines 61..67
              app/helpers/users_helper.rb on lines 70..76

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

              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

                  when 'in_process'
                    current = true if params[:circulation_status_in_process]
                    string << "<strong>" if current
                    c = CirculationStatus.find_by_name('In Process')
                    string << link_to("#{c.display_name.localize} (" + facet.count.to_s + ")", url_for(params.merge(:circulation_status_in_process => true, :circulation_statua_in_factory => nil, :page => nil, :view => nil)))
              Severity: Minor
              Found in app/helpers/manifestations_helper.rb and 1 other location - About 55 mins to fix
              app/helpers/manifestations_helper.rb on lines 186..190

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

              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

                  when 'in_factory'
                    current = true if params[:circulation_status_in_factory]
                    string << "<strong>" if current
                    c = CirculationStatus.find_by_name('In Factory')
                    string << link_to("#{c.display_name.localize} (" + facet.count.to_s + ")", url_for(params.merge(:circulation_status_in_factory => true, :circulation_status_in_process => nil, :page => nil, :view => nil)))
              Severity: Minor
              Found in app/helpers/manifestations_helper.rb and 1 other location - About 55 mins to fix
              app/helpers/manifestations_helper.rb on lines 181..185

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

              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

                  string << link_to("#{manifestation_type.display_name.localize} (" + facet.count.to_s + ")", url_for(params.merge(:manifestation_type => manifestation_type.name, :page => nil, :view => nil)))
              Severity: Minor
              Found in app/helpers/manifestations_helper.rb and 1 other location - About 15 mins to fix
              app/helpers/manifestations_helper.rb on lines 162..162

              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

                      unless manifestation.id == session[:manifestation_ids].last
                        links << link_to(t('page.next'), manifestation_path(session[:manifestation_ids][current_seq + 1]))
                      else
                        links << t('page.next').to_s
              Severity: Minor
              Found in app/helpers/manifestations_helper.rb and 1 other location - About 15 mins to fix
              app/helpers/manifestations_helper.rb on lines 57..60

              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

                    string << link_to("#{carrier_type.display_name.localize} (" + facet.count.to_s + ")", url_for(params.merge(:carrier_type => carrier_type.name, :page => nil, :view => nil)))
              Severity: Minor
              Found in app/helpers/manifestations_helper.rb and 1 other location - About 15 mins to fix
              app/helpers/manifestations_helper.rb on lines 172..172

              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

                      unless manifestation.id == session[:manifestation_ids].first
                        links << link_to(t('page.previous'), manifestation_path(session[:manifestation_ids][current_seq - 1]))
                      else
                        links << t('page.previous').to_s
              Severity: Minor
              Found in app/helpers/manifestations_helper.rb and 1 other location - About 15 mins to fix
              app/helpers/manifestations_helper.rb on lines 52..55

              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

                      unless nacsis_cat.ncid == ids_ary.first
                        links << link_to(t('page.previous'), params.merge(:ncid => ids_ary[current_seq - 1]))
                      else
                        links << t('page.previous').to_s
              Severity: Minor
              Found in app/helpers/manifestations_helper.rb and 1 other location - About 15 mins to fix
              app/helpers/manifestations_helper.rb on lines 80..83

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

              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

                      unless nacsis_cat.ncid == ids_ary.last
                        links << link_to(t('page.next'), params.merge(:ncid => ids_ary[current_seq + 1]))
                      else
                        links << t('page.next').to_s
              Severity: Minor
              Found in app/helpers/manifestations_helper.rb and 1 other location - About 15 mins to fix
              app/helpers/manifestations_helper.rb on lines 85..88

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

              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