publiclab/spectral-workbench

View on GitHub

Showing 127 of 127 total issues

Function updateLegend has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  updateLegend: function() {
    $W.updateLegendTimeout = null;

    var pos = $W.latestPosition;

Severity: Minor
Found in app/assets/javascripts/analyze.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

Function getCrossSection has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  getCrossSection: function(video) {
    // draw the new data on the top row of pixels of the canvas, overwriting what's there now
    if ($W.mobile) {
      // this is only for the deprecated mobile version
      $W.ctx.scale(3,1)
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

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

  def notify_commenters(new_comment, current_user)
    emails = []
    comments.each do |comment|
      emails << comment.email if comment != new_comment && (!current_user || (comment.author != current_user.login)) && comment.author != author
    end
Severity: Major
Found in app/models/spectra_set.rb and 1 other location - About 1 hr to fix
app/models/spectrum.rb on lines 473..484

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

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 notify_commenters(new_comment, current_user)
    emails = []
    comments.each do |comment|
      emails << comment.email if comment != new_comment && (!current_user || (comment.author != current_user.login)) && comment.author != author
    end
Severity: Major
Found in app/models/spectrum.rb and 1 other location - About 1 hr to fix
app/models/spectra_set.rb on lines 75..86

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

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

  def show
    @spectrum = Spectrum.find(params[:id])
    respond_with(@spectrum) do |format|
      format.html do
        # temporary routing until we deprecate 1.0 paths to /legacy
Severity: Minor
Found in app/controllers/spectrums_controller.rb - About 1 hr to fix

    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

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

              def clone_search
                @spectrum = Spectrum.find(params[:id])
                @calibrations = Spectrum.where(calibrated: true)
                                        .where('id != ?', @spectrum.id)
                                        .where('title LIKE ? OR notes LIKE ? OR author LIKE ?', "%#{params[:q]}%", "%#{params[:q]}%", "%#{params[:q]}%")
            Severity: Major
            Found in app/controllers/spectrums_controller.rb and 1 other location - About 1 hr to fix
            app/controllers/spectrums_controller.rb on lines 530..538

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

            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 compare_search
                @spectrum = Spectrum.find(params[:id])
                @spectra = Spectrum.where(calibrated: true)
                                   .where('id != ?', @spectrum.id)
                                   .where('title LIKE ? OR notes LIKE ? OR author LIKE ?', "%#{params[:q]}%", "%#{params[:q]}%", "%#{params[:q]}%")
            Severity: Major
            Found in app/controllers/spectrums_controller.rb and 1 other location - About 1 hr to fix
            app/controllers/spectrums_controller.rb on lines 520..528

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

            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

            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
              Severity
              Category
              Status
              Source
              Language