ncbo/bioportal_web_ui

View on GitHub
app/controllers/application_controller.rb

Summary

Maintainability
F
3 days
Test Coverage

File application_controller.rb has 527 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'uri'
require 'net/http'
require 'net/https'
require 'net/ftp'
require 'json'
Severity: Major
Found in app/controllers/application_controller.rb - About 1 day to fix

    Class ApplicationController has 45 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class ApplicationController < ActionController::Base
      helper :all # include all helpers, all the time
      helper_method :bp_config_json, :current_license, :using_captcha?
    
      # Pull configuration parameters for REST connection.
    Severity: Minor
    Found in app/controllers/application_controller.rb - About 6 hrs to fix

      Method get_class has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
      Open

        def get_class(params)
      
          if @ontology.flat?
      
            ignore_concept_param = params[:conceptid].nil? ||
      Severity: Minor
      Found in app/controllers/application_controller.rb - About 4 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 get_class has 60 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def get_class(params)
      
          if @ontology.flat?
      
            ignore_concept_param = params[:conceptid].nil? ||
      Severity: Major
      Found in app/controllers/application_controller.rb - About 2 hrs to fix

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

          def simplify_ontology_model(ont_model)
            id = nil
            if ont_model.instance_of? Hash
              id = ont_model['@id']
            elsif ont_model.instance_of? LinkedData::Client::Models::Ontology
        Severity: Minor
        Found in app/controllers/application_controller.rb - About 1 hr to fix

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

            def simplify_class_model(cls_model)
              # Simplify the class required required by the UI.
              # No modification of the class ontology here, see simplify_classes.
              # Default simple class model
              cls = { :id => nil, :ontology => nil, :prefLabel => nil, :uri => nil, :ui => nil, :obsolete => false }
          Severity: Minor
          Found in app/controllers/application_controller.rb - About 1 hr to fix

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

              def simplify_ontology_model(ont_model)
                id = nil
                if ont_model.instance_of? Hash
                  id = ont_model['@id']
                elsif ont_model.instance_of? LinkedData::Client::Models::Ontology
            Severity: Minor
            Found in app/controllers/application_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 redirect_new_api has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def redirect_new_api(class_view = false)
                # Hack to make ontologyid and conceptid work in addition to id and ontology params
                params[:ontology] = params[:ontology].nil? ? params[:ontologyid] : params[:ontology]
                # Error checking
                if params[:ontology].nil? || params[:id] && params[:ontology].nil?
            Severity: Minor
            Found in app/controllers/application_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 response_errors has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def response_errors(error_struct)
                error_struct = parse_response_body(error_struct)
                errors = {error: "There was an error, please try again"}
                return errors unless error_struct
                return errors unless error_struct.respond_to?(:errors)
            Severity: Minor
            Found in app/controllers/application_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 authorize_owner has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def authorize_owner(id=nil)
                if id.nil?
                  id = params[:id].to_i
                end
            
            
            Severity: Minor
            Found in app/controllers/application_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 struct_to_hash has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def struct_to_hash(struct)
                hash = {}
                struct.members.each do |attr|
                  next if [:links, :context].include?(attr)
                  if struct[attr].is_a?(Struct) || struct[attr].is_a?(OpenStruct)
            Severity: Minor
            Found in app/controllers/application_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

            Consider simplifying this complex logical expression.
            Open

                if @ontology.flat?
            
                  ignore_concept_param = params[:conceptid].nil? ||
                      params[:conceptid].empty? ||
                      params[:conceptid].eql?("root") ||
            Severity: Major
            Found in app/controllers/application_controller.rb - About 40 mins to fix

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

                def check_delete_mapping_permission(mappings)
                  # ensure mappings is an Array of mappings (some calls may provide only a single mapping instance)
                  mappings = [mappings] if mappings.instance_of? LinkedData::Client::Models::Mapping
                  return false if mappings.all? {|m| m.id.to_s.empty?}
                  delete_mapping_permission = false
              Severity: Minor
              Found in app/controllers/application_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 simplify_class_model has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def simplify_class_model(cls_model)
                  # Simplify the class required required by the UI.
                  # No modification of the class ontology here, see simplify_classes.
                  # Default simple class model
                  cls = { :id => nil, :ontology => nil, :prefLabel => nil, :uri => nil, :ui => nil, :obsolete => false }
              Severity: Minor
              Found in app/controllers/application_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 clean_empty_strings_from_params_arrays has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def clean_empty_strings_from_params_arrays(params = nil)
                  params ||= params()
                  params.keys.each do |k|
                    clean_empty_strings_from_params_arrays(params[k]) if params[k].is_a?(Hash)
                    params[k] = params[k].select {|e| !e.eql?("")} if params[k].is_a?(Array)
              Severity: Minor
              Found in app/controllers/application_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 params_string_for_redirect has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def params_string_for_redirect(params, options = {})
                  prefix = options[:prefix] || "?"
                  stop_words = options[:stop_words] || ["ontology", "controller", "action", "id", "acronym"]
                  params_array = []
                  params.each do |key,value|
              Severity: Minor
              Found in app/controllers/application_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 parse_json has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def parse_json(uri)
                  begin
                    response = Net::HTTP.get(URI(uri), { 'Authorization' => "apikey token=#{get_apikey}" })
                  rescue StandardError => e
                    @retries ||= 0
              Severity: Minor
              Found in app/controllers/application_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_recent_mappings has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def get_recent_mappings
                  recent_mappings = {
                      :mappings => [],
                      :classes => {}
                  }
              Severity: Minor
              Found in app/controllers/application_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_batch_results has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def get_batch_results(params)
                  begin
                    response = RestClient.post REST_URI_BATCH, params.to_json, :content_type => :json, :accept => :json, :authorization => "apikey token=#{get_apikey}"
                  rescue Exception => error
                    @retries ||= 0
              Severity: Minor
              Found in app/controllers/application_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