ncbo/bioportal_web_ui

View on GitHub
app/controllers/application_controller.rb

Summary

Maintainability
F
4 days
Test Coverage

File application_controller.rb has 535 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

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

      def get_class(params, submission)
        lang = helpers.request_lang(submission)
    
        if @ontology.flat?
          ignore_concept_param = params[:conceptid].nil? ||
    Severity: Minor
    Found in app/controllers/application_controller.rb - About 7 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

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

        def get_class(params, submission)
          lang = helpers.request_lang(submission)
      
          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 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 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 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

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

            Consider simplifying this complex logical expression.
            Open

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

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

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

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

                      @root.children = roots.sort{|x,y|
                        x.prefLabel = helpers.link_last_part(x.id) if x.prefLabel.to_s.empty?
                        y.prefLabel = helpers.link_last_part(y.id) if y.prefLabel.to_s.empty?
                        (x.prefLabel || "").downcase <=> (y.prefLabel || "").downcase}
              Severity: Minor
              Found in app/controllers/application_controller.rb and 1 other location - About 45 mins to fix
              app/controllers/application_controller.rb on lines 433..436

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

              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

                      @root.children = rootNode.sort{|x,y|
                        x.prefLabel = helpers.link_last_part(x.id) if x.prefLabel.to_s.empty?
                        y.prefLabel = helpers.link_last_part(y.id) if y.prefLabel.to_s.empty?
                        (x.prefLabel || "").downcase <=> (y.prefLabel || "").downcase}
              Severity: Minor
              Found in app/controllers/application_controller.rb and 1 other location - About 45 mins to fix
              app/controllers/application_controller.rb on lines 393..396

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

              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