concord-consortium/rigse

View on GitHub
rails/app/controllers/api/v1/materials_controller.rb

Summary

Maintainability
D
2 days
Test Coverage

File materials_controller.rb has 454 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class API::V1::MaterialsController < API::APIController
  include Materials::DataHelpers

  #
  # Default number of related materials to return
Severity: Minor
Found in rails/app/controllers/api/v1/materials_controller.rb - About 6 hrs to fix

    Method add_materials_standard has 61 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def add_materials_standard
    
        key     = ENV['ASN_API_KEY']
        uri     = params[:identifier]
        type    = params[:material_type]
    Severity: Major
    Found in rails/app/controllers/api/v1/materials_controller.rb - About 2 hrs to fix

      Method get_standard_statements has 50 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def get_standard_statements
      
          key                     = ENV['ASN_API_KEY']
          document_id             = params[:asn_document_id]
          statement_notation_q    = params[:asn_statement_notation_query]
      Severity: Minor
      Found in rails/app/controllers/api/v1/materials_controller.rb - About 2 hrs to fix

        Method add_favorite has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def add_favorite
        
            if !current_user || current_user.anonymous?
              render json: {:message => "Cannot add favorite for non-logged in user."},
                            :status => 400
        Severity: Minor
        Found in rails/app/controllers/api/v1/materials_controller.rb - About 1 hr to fix

          Method remove_favorite has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def remove_favorite
          
              if !current_user || current_user.anonymous?
                render json: {:message => "Cannot remove favorite for non-logged in user."}, :status => 400
                return
          Severity: Minor
          Found in rails/app/controllers/api/v1/materials_controller.rb - About 1 hr to fix

            Method show has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def show
            
                type            = params[:material_type]
                id              = params[:id]
                include_related = params.has_key?(:include_related)     ?
            Severity: Minor
            Found in rails/app/controllers/api/v1/materials_controller.rb - About 1 hr to fix

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

                def get_standard_statements
              
                  key                     = ENV['ASN_API_KEY']
                  document_id             = params[:asn_document_id]
                  statement_notation_q    = params[:asn_statement_notation_query]
              Severity: Minor
              Found in rails/app/controllers/api/v1/materials_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 add_materials_standard has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def add_materials_standard
              
                  key     = ENV['ASN_API_KEY']
                  uri     = params[:identifier]
                  type    = params[:material_type]
              Severity: Minor
              Found in rails/app/controllers/api/v1/materials_controller.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 show has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def show
              
                  type            = params[:material_type]
                  id              = params[:id]
                  include_related = params.has_key?(:include_related)     ?
              Severity: Minor
              Found in rails/app/controllers/api/v1/materials_controller.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 process_asn_response has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def process_asn_response(hits, applied_map = {})
              
                  #
                  # Find our local peristed copy of the document these statements belong to.
                  #
              Severity: Minor
              Found in rails/app/controllers/api/v1/materials_controller.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

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

                def featured
                  materials = ExternalActivity.published.where(:is_featured => true).includes([:user]).to_a
              
                  if params[:prioritize].present?
                    prioritize = params[:prioritize].split(',').map { |p| p.to_i rescue 0 }
              Severity: Minor
              Found in rails/app/controllers/api/v1/materials_controller.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

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

                def add_favorite
              
                  if !current_user || current_user.anonymous?
                    render json: {:message => "Cannot add favorite for non-logged in user."},
                                  :status => 400
              Severity: Minor
              Found in rails/app/controllers/api/v1/materials_controller.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

              Avoid too many return statements within this method.
              Open

                    return
              Severity: Major
              Found in rails/app/controllers/api/v1/materials_controller.rb - About 30 mins to fix

                Method assign_to_class has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def assign_to_class
                    # only add/delete if assign parameter exists to avoid deleting data on a bad request
                    status = 200
                    if params[:assign].present?
                      portal_clazz = Portal::Clazz.find(params[:class_id])
                Severity: Minor
                Found in rails/app/controllers/api/v1/materials_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 remove_favorite has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def remove_favorite
                
                    if !current_user || current_user.anonymous?
                      render json: {:message => "Cannot remove favorite for non-logged in user."}, :status => 400
                      return
                Severity: Minor
                Found in rails/app/controllers/api/v1/materials_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 get_favorites has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def get_favorites
                
                    if !current_user || current_user.anonymous?
                      render json: {:message => "Cannot retrieve favorites for non-logged in user."}, :status => 400
                      return
                Severity: Minor
                Found in rails/app/controllers/api/v1/materials_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

                There are no issues that match your filters.

                Category
                Status