publiclab/spectral-workbench

View on GitHub
app/controllers/spectrums_controller.rb

Summary

Maintainability
F
4 days
Test Coverage

Method create has a Cognitive Complexity of 95 (exceeds 5 allowed). Consider refactoring.
Open

  def create # rubocop:disable Metrics/AbcSize
    if logged_in? || params[:token] && User.find_by_token(params[:token])

      user = current_user || User.find_by_token(params[:token])
      params[:spectrum][:json] = params[:spectrum][:data] if params[:spectrum] && params[:spectrum][:data]
Severity: Minor
Found in app/controllers/spectrums_controller.rb - About 1 day 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 spectrums_controller.rb has 428 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'will_paginate/array'
class SpectrumsController < ApplicationController
  respond_to :html, :xml, :js, :csv, :json
  # expand this:
  protect_from_forgery only: %i(clone_calibration extract calibrate save)
Severity: Minor
Found in app/controllers/spectrums_controller.rb - About 6 hrs to fix

    Class SpectrumsController has 34 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class SpectrumsController < ApplicationController
      respond_to :html, :xml, :js, :csv, :json
      # expand this:
      protect_from_forgery only: %i(clone_calibration extract calibrate save)
      # http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html
    Severity: Minor
    Found in app/controllers/spectrums_controller.rb - About 4 hrs to fix

      Method create has 81 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def create # rubocop:disable Metrics/AbcSize
          if logged_in? || params[:token] && User.find_by_token(params[:token])
      
            user = current_user || User.find_by_token(params[:token])
            params[:spectrum][:json] = params[:spectrum][:data] if params[:spectrum] && params[:spectrum][:data]
      Severity: Major
      Found in app/controllers/spectrums_controller.rb - About 3 hrs to fix

        Method show has a Cognitive Complexity of 17 (exceeds 5 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 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 update has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

          def update
            @spectrum = Spectrum.find(params[:id])
            require_ownership(@spectrum)
        
            @spectrum.title = params[:spectrum][:title] unless params[:spectrum].nil? || params[:spectrum][:title].nil?
        Severity: Minor
        Found in app/controllers/spectrums_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 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 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 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

          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

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

                    format.html  { render action: 'new' }
                    format.xml   { render xml: @spectrum.errors, status: :unprocessable_entity }
                    format.json  { render json: @spectrum.errors, status: :unprocessable_entity }
          Severity: Minor
          Found in app/controllers/spectrums_controller.rb and 1 other location - About 20 mins to fix
          app/controllers/spectrums_controller.rb on lines 287..289

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

          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

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

                      format.html  { render action: 'new' }
                      format.xml   { render xml: @spectrum.errors, status: :unprocessable_entity }
                      format.json  { render json: @spectrum.errors, status: :unprocessable_entity }
          Severity: Minor
          Found in app/controllers/spectrums_controller.rb and 1 other location - About 20 mins to fix
          app/controllers/spectrums_controller.rb on lines 297..299

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

          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 embed
              @spectrum = Spectrum.find(params[:id])
              @width = (params[:width] || 500).to_i
              @height = (params[:height] || 300).to_i
              render layout: false
          Severity: Minor
          Found in app/controllers/spectrums_controller.rb and 1 other location - About 15 mins to fix
          app/controllers/sets_controller.rb on lines 59..64

          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

          There are no issues that match your filters.

          Category
          Status