psu-libraries/psulib_blacklight

View on GitHub

Showing 30 of 39 total issues

Function SpecialRequestLink has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
Open

const SpecialRequestLink = ({ holding, locationText }) => {
  const [hasData, setHasData] = useState(false);
  const [showSpinner, setShowSpinner] = useState(true);
  const [url, setUrl] = useState('#');
  const { catkey } = holding;
Severity: Minor
Found in app/javascript/availability/components/special_request_link.jsx - About 7 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

File index.js has 456 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * @file
 * Real Time Availability
 */

Severity: Minor
Found in app/javascript/availability/index.js - About 6 hrs to fix

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

                    {locationData.supplement.length > 0 && (
                      <li>
                        <div className="h6 mt-2">
                          <span className="sr-only">{locationName}</span>
                          Supplements
Severity: Major
Found in app/javascript/availability/components/summary_holdings.jsx and 1 other location - About 5 hrs to fix
app/javascript/availability/components/summary_holdings.jsx on lines 75..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 138.

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

                    {locationData.index.length > 0 && (
                      <li>
                        <div className="h6 mt-2">
                          <span className="sr-only">{locationName}</span>
                          Indexes
Severity: Major
Found in app/javascript/availability/components/summary_holdings.jsx and 1 other location - About 5 hrs to fix
app/javascript/availability/components/summary_holdings.jsx on lines 90..103

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

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

File catalog_controller.rb has 373 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class CatalogController < ApplicationController
  include BlacklightAdvancedSearch::Controller
  include BlacklightRangeLimit::ControllerOverride
  include Blacklight::Catalog
  include Blacklight::Configurable
Severity: Minor
Found in app/controllers/catalog_controller.rb - About 4 hrs to fix

Function loadAvailability has 70 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  loadAvailability() {
    const titleIDs = [];
    const summaryHoldings = {};

    // Get the catkeys
Severity: Major
Found in app/javascript/availability/index.js - About 2 hrs to fix

Function processBoundParents has 68 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  processBoundParents(boundHoldings, allHoldings, summaryHoldings) {
    const catkeys = Object.keys(boundHoldings);

    let itemIDs = [];
    $.each(catkeys, (i, catkey) => {
Severity: Major
Found in app/javascript/availability/index.js - About 2 hrs to fix

Function blCheckboxSubmit has 68 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  $.fn.blCheckboxSubmit = function (argOpts) {
    this.each(function () {
      const options = $.extend({}, $.fn.blCheckboxSubmit.defaults, argOpts);

      const form = $(this);
Severity: Major
Found in app/javascript/blacklight_overrides/javascripts/checkbox_submit.js - About 2 hrs to fix

Class SolrManager has 22 methods (exceeds 20 allowed). Consider refactoring.
Open

  class SolrManager
    ALLOWED_TIME_TO_RESPOND = 30

    attr_reader :config

Severity: Minor
Found in lib/psulib_blacklight/solr_manager.rb - About 2 hrs to fix

Function availabilityDisplay has 56 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  availabilityDisplay(allHoldings, summaryHoldings) {
    $('.availability').each(function () {
      const availabilityHTML = $(this);
      const catkey = availabilityHTML.data('keys');
      const isOnlineOnOrderOnly = availabilityHTML.data('isOnlineOnOrderOnly');
Severity: Major
Found in app/javascript/availability/index.js - About 2 hrs to fix

Function setGooglePreview has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

export default function setGooglePreview() {
  const element = document.getElementById('google-preview');
  const urlComponents = {
    googlePreviewUrl: '/links/google-preview-data',
    searchItem: element?.dataset?.searchItem,

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 getBoundHoldings has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  getBoundHoldings(boundHoldings, titleInfo) {
    boundHoldings[titleInfo.catkey] = [];

    titleInfo.jQueryObj.children('BoundwithLinkInfo').each(function () {
      const linkedAsParent = $(this).children('linkedAsParent').text();
Severity: Minor
Found in app/javascript/availability/index.js - About 1 hr to fix

Function clicked has 34 lines of code (exceeds 25 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 1 hr to fix

Function setGooglePreview has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export default function setGooglePreview() {
  const element = document.getElementById('google-preview');
  const urlComponents = {
    googlePreviewUrl: '/links/google-preview-data',
    searchItem: element?.dataset?.searchItem,

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

    def get_item_location_data(holding)
      item_location_data = []
      if holding['ItemInfo'].is_a?(Array)
        holding['ItemInfo'].each do |item|
          if item_location_data.size >= 3
Severity: Minor
Found in app/services/holdings_request_service.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 index has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def index
    cache_key = nil
    # No other params presents indicates we are on the homepage
    if params.keys.eql? %w[controller action]
      cache_key = "#{params['controller']}/#{params['action']}facet_query"
Severity: Minor
Found in app/controllers/catalog_controller.rb - About 1 hr to fix

Function availabilityDataStructurer has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  availabilityDataStructurer(holdingMetadata) {
    const availabilityStructuredData = [];
    let holdingData = [];
    let pluralize = '';
    let library = '';
Severity: Minor
Found in app/javascript/availability/index.js - About 1 hr to fix

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

      def url
        url_opts = @url_opts.merge(({ id: @document } if @document) || {})
        if @action.path
          helpers.public_send(@action.path, url_opts)
        elsif url_opts[:id].class.respond_to?(:model_name)
Severity: Minor
Found in app/components/blacklight/document/action_component.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 follow_redirects has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def follow_redirects(url)
      host = URI.parse(url).host

      # Skip any further redirect business if we already know that we're going to get a
      # response with good CORS headers.
Severity: Minor
Found in app/models/solr_document.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

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.sms.text.#{field}"
Severity: Minor
Found in app/models/concerns/blacklight/document/sms.rb and 1 other location - About 45 mins to fix
app/models/concerns/blacklight/document/email.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

Severity
Category
Status
Source
Language