datacite/lupo

View on GitHub
app/models/doi.rb

Summary

Maintainability
F
2 wks
Test Coverage
F
28%

File doi.rb has 2078 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "maremma"
require "benchmark"

class Doi < ApplicationRecord
  self.ignored_columns += [:publisher]
Severity: Major
Found in app/models/doi.rb - About 5 days to fix

    Class Doi has 156 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Doi < ApplicationRecord
      self.ignored_columns += [:publisher]
      PUBLISHER_JSON_SCHEMA = Rails.root.join("app", "models", "schemas", "doi", "publisher.json")
      audited only: %i[doi url creators contributors titles publisher_obj publication_year types descriptions container sizes formats version_info language dates identifiers related_identifiers related_items funding_references geo_locations rights_list subjects schema_version content_url landing_page aasm_state source reason]
    
    
    Severity: Major
    Found in app/models/doi.rb - About 3 days to fix

      Method query has a Cognitive Complexity of 85 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.query(query, options = {})
          # support scroll api
          # map function is small performance hit
          if options[:scroll_id].present? && options.dig(:page, :scroll)
            begin
      Severity: Minor
      Found in app/models/doi.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

      Method query has 250 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.query(query, options = {})
          # support scroll api
          # map function is small performance hit
          if options[:scroll_id].present? && options.dig(:page, :scroll)
            begin
      Severity: Major
      Found in app/models/doi.rb - About 1 day to fix

        Method convert_affiliation_by_id has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.convert_affiliation_by_id(options = {})
            return nil if options[:id].blank?
        
            id = options[:id].to_i
            count = 0
        Severity: Minor
        Found in app/models/doi.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

        Method as_indexed_json has 88 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def as_indexed_json(_options = {})
            {
              "id" => uid,
              "uid" => uid,
              "doi" => doi,
        Severity: Major
        Found in app/models/doi.rb - About 3 hrs to fix

          Method convert_affiliation_by_id has 75 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.convert_affiliation_by_id(options = {})
              return nil if options[:id].blank?
          
              id = options[:id].to_i
              count = 0
          Severity: Major
          Found in app/models/doi.rb - About 3 hrs to fix

            Method query_aggregations has 67 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def self.query_aggregations(disable_facets: false)
                if !disable_facets
                  {
                    # number of resourceTypeGeneral increased from 16 to 28 in schema 4.4
                    resource_types: { terms: { field: "resource_type_id_and_name", size: 30, min_doc_count: 1 } },
            Severity: Major
            Found in app/models/doi.rb - About 2 hrs to fix

              Method add_index_type has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.add_index_type(options = {})
                  return nil if options[:from_id].blank?
              
                  from_id = options[:from_id].to_i
                  until_id = (options[:until_id] || (from_id + 499)).to_i
              Severity: Minor
              Found in app/models/doi.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 import_one has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.import_one(doi_id: nil, id: nil)
                  if doi_id
                    doi = Doi.where(doi: doi_id).first
                  else
                    doi = Doi.where(id: id).first
              Severity: Minor
              Found in app/models/doi.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 migrate_landing_page has 40 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def self.migrate_landing_page(_options = {})
                  Rails.logger.info "Starting migration"
              
                  # Handle camel casing first.
                  Doi.where.not("last_landing_page_status_result" => nil).find_each do |doi|
              Severity: Minor
              Found in app/models/doi.rb - About 1 hr to fix

                Method convert_container_by_id has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                  def self.convert_container_by_id(options = {})
                    return nil if options[:id].blank?
                
                    id = options[:id].to_i
                    count = 0
                Severity: Minor
                Found in app/models/doi.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 transfer has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                  def self.transfer(options = {})
                    if options[:client_id].blank?
                      Rails.logger.error "[Transfer] No client provided."
                      return nil
                    end
                Severity: Minor
                Found in app/models/doi.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 add_index_type has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def self.add_index_type(options = {})
                    return nil if options[:from_id].blank?
                
                    from_id = options[:from_id].to_i
                    until_id = (options[:until_id] || (from_id + 499)).to_i
                Severity: Minor
                Found in app/models/doi.rb - About 1 hr to fix

                  Method import_one has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def self.import_one(doi_id: nil, id: nil)
                      if doi_id
                        doi = Doi.where(doi: doi_id).first
                      else
                        doi = Doi.where(id: id).first
                  Severity: Minor
                  Found in app/models/doi.rb - About 1 hr to fix

                    Method convert_container_by_id has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def self.convert_container_by_id(options = {})
                        return nil if options[:id].blank?
                    
                        id = options[:id].to_i
                        count = 0
                    Severity: Minor
                    Found in app/models/doi.rb - About 1 hr to fix

                      Method migrate_landing_page has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def self.migrate_landing_page(_options = {})
                          Rails.logger.info "Starting migration"
                      
                          # Handle camel casing first.
                          Doi.where.not("last_landing_page_status_result" => nil).find_each do |doi|
                      Severity: Minor
                      Found in app/models/doi.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 update_agency has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def update_agency
                          if agency.blank? || agency.casecmp?("datacite")
                            self.agency = "datacite"
                            self.type = "DataciteDoi"
                          elsif agency.casecmp?("crossref")
                      Severity: Minor
                      Found in app/models/doi.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 update_agency has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        def update_agency
                          if agency.blank? || agency.casecmp?("datacite")
                            self.agency = "datacite"
                            self.type = "DataciteDoi"
                          elsif agency.casecmp?("crossref")
                      Severity: Minor
                      Found in app/models/doi.rb - About 1 hr to fix

                        Method delete_dois_by_prefix has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def self.delete_dois_by_prefix(prefix, options = {})
                            if prefix.blank?
                              Rails.logger.error "[Error] No prefix provided."
                              return nil
                            end
                        Severity: Minor
                        Found in app/models/doi.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 hide_dois_by_prefix has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def self.hide_dois_by_prefix(prefix, options = {})
                            if prefix.blank?
                              Rails.logger.error "[Error] No prefix provided."
                              return nil
                            end
                        Severity: Minor
                        Found in app/models/doi.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 loop_through_dois has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def self.loop_through_dois(options = {})
                            size = (options[:size] || 1000).to_i
                            cursor = options[:cursor] || []
                            filter = options[:filter] || {}
                            label = options[:label] || ""
                        Severity: Minor
                        Found in app/models/doi.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 check_contributors has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def check_contributors
                            Array.wrap(contributors).each do |c|
                              errors.add(:contributors, "Contributor '#{c}' should be an object instead of a string.") unless c.is_a?(Hash)
                              if schema_version == "http://datacite.org/schema/kernel-4"
                                errors.add(:contributors, "Contributor type #{c['contributorType']} is not supported in schema 4.") unless %w(ContactPerson DataCollector DataCurator DataManager Distributor Editor HostingInstitution Other Producer ProjectLeader ProjectManager ProjectMember RegistrationAgency RegistrationAuthority RelatedPerson ResearchGroup RightsHolder Researcher Sponsor Supervisor WorkPackageLeader).include?(c["contributorType"])
                        Severity: Minor
                        Found in app/models/doi.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 set_url has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def self.set_url
                            response = Doi.query("-url:* (-aasm_status:draft)", page: { size: 1, cursor: [] })
                            message = "#{response.results.total} DOIs with no URL found in the database."
                        
                            if response.results.total > 0
                        Severity: Minor
                        Found in app/models/doi.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 find_by_ids has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def self.find_by_ids(ids, options = {})
                            ids = ids.split(",") if ids.is_a?(String)
                        
                            options[:page] ||= {}
                            options[:page][:number] ||= 1
                        Severity: Minor
                        Found in app/models/doi.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 set_minted has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def self.set_minted
                            response = Doi.query("+aasm_state:draft +url:*", page: { size: 1, cursor: [] })
                            message = "#{response.results.total} draft DOIs with URL found in the database."
                        
                            if response.results.total > 0
                        Severity: Minor
                        Found in app/models/doi.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 convert_publisher_by_id has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def self.convert_publisher_by_id(options = {})
                            return nil if options[:id].blank?
                        
                            id = options[:id].to_i
                            count = 0
                        Severity: Minor
                        Found in app/models/doi.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

                              unless Array.wrap(doi.creators).all? { |c| c.is_a?(Hash) && c["affiliation"].is_a?(Array) && c["affiliation"].all? { |a| a.is_a?(Hash) } } && Array.wrap(doi.contributors).all? { |c| c.is_a?(Hash) && c["affiliation"].is_a?(Array) && c["affiliation"].all? { |a| a.is_a?(Hash) } }
                                Rails.logger.error "[MySQL] Error converting affiliations for doi #{doi.doi}: creators #{doi.creators.inspect} contributors #{doi.contributors.inspect}."
                                fail TypeError, "Affiliation for doi #{doi.doi} is of wrong type" if Rails.env.test?
                              end
                        Severity: Major
                        Found in app/models/doi.rb - About 40 mins to fix

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

                            def self.set_handle
                              response = Doi.query("-registered:* +url:* -aasm_state:draft -provider_id:europ -agency:crossref", page: { size: 1, cursor: [] })
                              message = "#{response.results.total} DOIs found that are not registered in the Handle system."
                          
                              if response.results.total > 0
                          Severity: Minor
                          Found in app/models/doi.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

                          There are no issues that match your filters.

                          Category
                          Status