psu-libraries/psulib_blacklight

View on GitHub

Showing 30 of 39 total issues

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

  class HathiLinkComponent < HathiGoogleLinksComponent
    def search_item
      return nil if free_to_read?

      return "oclc/#{oclc}" if oclc.present?
Severity: Minor
Found in app/components/external_links/hathi_link_component.rb and 1 other location - About 45 mins to fix
app/components/external_links/google_preview_link_component.rb on lines 4..20

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

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

    ['title', 'latin_title', 'author', 'corporate_author', 'conference_author',
     'published', 'edition', 'format', 'language'].each do |field|
      if semantics[field.to_sym].present?
        value = semantics[field.to_sym]
        label = "blacklight.email.text.#{field}"
Severity: Minor
Found in app/models/concerns/blacklight/document/email.rb and 1 other location - About 45 mins to fix
app/models/concerns/blacklight/document/sms.rb on lines 9..14

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

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

  class GooglePreviewLinkComponent < HathiGoogleLinksComponent
    def search_item
      return nil if free_to_read?

      return "LCCN:#{lccn}" if lccn.present?
Severity: Minor
Found in app/components/external_links/google_preview_link_component.rb and 1 other location - About 45 mins to fix
app/components/external_links/hathi_link_component.rb on lines 4..20

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

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

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

    def get_data_from_call_info(call_info)
      availability = []
      call_info.each do |holding|
        if availability.size >= 30
          @view_more = true
Severity: Minor
Found in app/services/holdings_request_service.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

Function clicked has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  async clicked() {
    for (let i = 0; i < this.forms.length; i += 1) {
      if (!this.checked(i)) {
        this.forms[i].querySelector('span').innerHTML =
          this.forms[i].getAttribute('data-inprogress');
Severity: Minor
Found in app/javascript/psulib_blacklight/javascripts/checkbox_submit_all.js - 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 login has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def login
    session[:groups] = request.env.fetch(Settings.groups_header, '').split(',')
    redirect_location = params['fullpath'] || stored_location_for(User) || '/'
    if current_user
      flash[:success] = I18n.t('blackcat.successful_login')
Severity: Minor
Found in app/controllers/application_controller.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 generate_links has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def generate_links(search_type, options)
      result = []
      options[:value].zip(strict_titles(search_type, options)).each do |item, zipped|
        lnk = link_to(item,
                      "/?#{search_query(search_type)}=#{CGI.escape(zipped || item)}",
Severity: Minor
Found in app/helpers/search_links_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 limit_clause_count has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def limit_clause_count(solr_parameters)
    return unless query_present?(solr_parameters)

    length = case blacklight_params['search_field']
             when 'all_fields'
Severity: Minor
Found in app/models/clause_count_limiter.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 to_email_text has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def to_email_text
    semantics = to_semantic_values
    body = []
    ['title', 'latin_title', 'author', 'corporate_author', 'conference_author',
     'published', 'edition', 'format', 'language'].each do |field|
Severity: Minor
Found in app/models/concerns/blacklight/document/email.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 pivot_facet_child_in_params? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def pivot_facet_child_in_params?(field_name, item, pivot_in_params = false)
    pivot_in_params = true if pivot_facet_in_params?(field_name, item)
    if item.items.present?
      item.items.each do |pivot_item|
        pivot_in_params = true if pivot_facet_child_in_params?(pivot_item.field, pivot_item)
Severity: Minor
Found in app/helpers/facets_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

Severity
Category
Status
Source
Language