publiclab/spectral-workbench

View on GitHub

Showing 84 of 127 total issues

Method errors_for has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def errors_for(object, message = nil)
    html = ''
    unless object.nil? || object.errors.blank?
      html << "<div class='alert alert-error #{object.class.name.humanize.downcase}Errors'>\n"
      html << if message.blank?
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 spectraset has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def spectraset
    @set = SpectraSet.find(params[:id])
    @comment = Comment.new(
      spectra_set_id: @set.id,
      body: params[:comment][:body],
Severity: Minor
Found in app/controllers/comments_controller.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

Function resetHeightIndicators has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  resetHeightIndicators: function(legacy) {
    if ($W.rotated) {
      if (legacy != true) $('#heightIndicator')[0].style.marginLeft = parseInt($W.width_percent*320)+'px';
      if (legacy != true) $('#heightIndicatorPrev')[0].style.marginLeft = parseInt($W.width_percent*$('#preview').width())+'px';
    } else {
Severity: Minor
Found in app/assets/javascripts/capture.js - 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 update has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def update
    @set = SpectraSet.find params[:id]
    if @set.user_id == current_user.id || current_user.role == 'admin'
      @set.notes = params[:notes] if params[:notes]
      @set.title = params[:title] if params[:title]
Severity: Minor
Found in app/controllers/sets_controller.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

Function auto_detect_sample_row has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  auto_detect_sample_row: function() {
        
    // We need a separate canvas to draw the snapshot, whenever we try to auto detect the sample row.
    if ($('#autoDetectCanvas').length == 0) {
      $('body').append("<canvas style='display:none;' id='autoDetectCanvas'></canvas>")
Severity: Minor
Found in app/assets/javascripts/capture.js - 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 add has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def add
    @set = SpectraSet.find params[:id]
    @spectrum = Spectrum.find params[:spectrum_id]
    if @set.user_id == current_user.id || current_user.role == 'admin'
      # be sure it's not already included:
Severity: Minor
Found in app/controllers/sets_controller.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 require_ownership has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def require_ownership(datum)
    data_type = self.class.name == 'SpectrumsController' ? :spectrum : :set

    if logged_in? && (current_user.role == 'admin' || current_user.id == datum.user_id)
      true
Severity: Minor
Found in app/controllers/application_controller.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 livesearch has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def livesearch
    data = ActiveSupport::JSON.decode('{' + params[:data] + '}')
    bins = (10...640).step(10)
    types = %w(a r g b)
    range = 50
Severity: Minor
Found in app/controllers/match_controller.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 livesearch has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def livesearch
    data = ActiveSupport::JSON.decode('{' + params[:data] + '}')
    bins = (10...640).step(10)
    types = %w(a r g b)
    range = 50
Severity: Minor
Found in app/controllers/match_controller.rb - About 1 hr to fix

    Method spectrum has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def spectrum
        @spectrum = Spectrum.find(params[:id])
        @comment = @spectrum.comments.new(
          body: params[:comment][:body],
          user_id: current_user.id
    Severity: Minor
    Found in app/controllers/comments_controller.rb - About 1 hr to fix

      Function save has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        $W.save = function(calibration) {
      
          if (!calibration) {
      
            $("#calibration_id").val("calibration"); // calibrate later
      Severity: Minor
      Found in app/assets/javascripts/upload.js - About 1 hr to fix

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

          def spectraset
            @set = SpectraSet.find(params[:id])
            @comment = Comment.new(
              spectra_set_id: @set.id,
              body: params[:comment][:body],
        Severity: Minor
        Found in app/controllers/comments_controller.rb - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

                      if (check_slope(1,i) && (i+min_width < pixels.length && i-min_width > 0) && Math.abs(pixels[i]['average']-pixels[i+min_width]['average'])/min_width >= min_slope && Math.abs(pixels[i]['average']-pixels[i-min_width]['average'])/min_width >= min_slope && pixels[i]['average']-pixels[i-min_width]['average'] > min_height && pixels[i]['average']-pixels[i+min_width]['average'] > min_height) { 
                        // it's a peak pixel, add it to peak pixel list
                        peaks.push(pixels[i]) // here, adding the entire pixel object, including separate rgb and wavelength values
                        peaks[peaks.length-1]['index'] = i // save the pixel index too
                        // be aware of non-calibrated spectra
          Severity: Major
          Found in app/assets/javascripts/api.js - About 1 hr to fix

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

              def choose
                params[:id] = params[:id].to_s
            
                comparison = if params[:id] == 'calibration' # special case; include linearCalibration too
                               "LIKE 'linearCalibration' OR tags.name LIKE"
            Severity: Minor
            Found in app/controllers/spectrums_controller.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 get_bins has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def get_bins(wavelength)
                base = (wavelength / 10) * 10
                diff = wavelength - base
            
                if base < 10 || base > 1490
            Severity: Minor
            Found in app/models/spectrum.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 index has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def index
                id = params[:id]
            
                if id.nil? # No need to search anything
                  flash[:error] = 'ID is required for matching'
            Severity: Minor
            Found in app/controllers/match_controller.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 update has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def update
                @macro = Macro.find params[:id]
                if logged_in?
                  if @macro.user_id == current_user.id
                    @macro.title = params[:title]
            Severity: Minor
            Found in app/controllers/macros_controller.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 generate_hashed_values has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def generate_hashed_values
                lines = latest_json_data['lines']
            
                values = {}
                counts = {}
            Severity: Minor
            Found in app/models/spectrum.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 latest has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def latest
                spectrum = Spectrum.find(params[:id])
                if spectrum.snapshots.count.positive?
                  @snapshot = spectrum.latest_snapshot
                  is_snapshot = true
            Severity: Minor
            Found in app/controllers/spectrums_controller.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

            Avoid deeply nested control flow statements.
            Open

                      if (green == 255) $W.data[4].data.push([w,100])
            Severity: Major
            Found in app/assets/javascripts/capture.js - About 45 mins to fix
              Severity
              Category
              Status
              Source
              Language