datacite/lupo

View on GitHub
app/models/event.rb

Summary

Maintainability
F
6 days
Test Coverage
F
30%

File event.rb has 878 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Event < ApplicationRecord
  # include helper module for query caching
  include Cacheable

  # include event processing
Severity: Major
Found in app/models/event.rb - About 2 days to fix

    Class Event has 47 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Event < ApplicationRecord
      # include helper module for query caching
      include Cacheable
    
      # include event processing
    Severity: Minor
    Found in app/models/event.rb - About 6 hrs to fix

      Method import_doi has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.import_doi(id, options = {})
          doi_id = validate_doi(id)
          return nil if doi_id.blank?
      
          # check whether DOI has been stored with DataCite already
      Severity: Minor
      Found in app/models/event.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 query_aggregations has 69 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.query_aggregations
          {
            sources: { terms: { field: "source_id", size: 10, min_doc_count: 1 } },
            prefixes: { terms: { field: "prefix", size: 10, min_doc_count: 1 } },
            occurred: {
      Severity: Major
      Found in app/models/event.rb - About 2 hrs to fix

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

          def self.import_doi(id, options = {})
            doi_id = validate_doi(id)
            return nil if doi_id.blank?
        
            # check whether DOI has been stored with DataCite already
        Severity: Major
        Found in app/models/event.rb - About 2 hrs to fix

          Method import_by_id has 57 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.import_by_id(options = {})
              return nil if options[:id].blank?
          
              id = options[:id].to_i
              index =
          Severity: Major
          Found in app/models/event.rb - About 2 hrs to fix

            Method set_source_and_target_doi has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def set_source_and_target_doi
                return nil unless subj_id && obj_id
            
                case relation_type_id
                when *REFERENCE_RELATION_TYPES
            Severity: Minor
            Found in app/models/event.rb - About 1 hr to fix

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

                def as_indexed_json(_options = {})
                  {
                    "uuid" => uuid,
                    "subj_id" => subj_id,
                    "obj_id" => obj_id,
              Severity: Minor
              Found in app/models/event.rb - About 1 hr to fix

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

                  def self.update_registrant(options = {})
                    size = (options[:size] || 1_000).to_i
                    cursor = (options[:cursor] || [])
                    # ra = options[:ra] || "crossref"
                    source_id = options[:source_id] || "datacite-crossref,crossref"
                Severity: Minor
                Found in app/models/event.rb - About 1 hr to fix

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

                    def self.subj_id_check(options = {})
                      size = (options[:size] || 1_000).to_i
                      cursor = [options[:from_id], options[:until_id]]
                  
                      response =
                  Severity: Minor
                  Found in app/models/event.rb - About 1 hr to fix

                    Method update_datacite_orcid_auto_update has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def self.update_datacite_orcid_auto_update(options = {})
                        size = (options[:size] || 1_000).to_i
                        cursor = (options[:cursor] || []).to_i
                    
                        response =
                    Severity: Minor
                    Found in app/models/event.rb - About 1 hr to fix

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

                        def self.update_datacite_ra(options = {})
                          size = (options[:size] || 1_000).to_i
                          cursor = (options[:cursor] || [])
                          ra = options[:ra] || "crossref"
                          source_id = "datacite-#{ra}"
                      Severity: Minor
                      Found in app/models/event.rb - About 1 hr to fix

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

                          def self.import_by_id(options = {})
                            return nil if options[:id].blank?
                        
                            id = options[:id].to_i
                            index =
                        Severity: Minor
                        Found in app/models/event.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_crossref has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          def self.update_crossref(options = {})
                            size = (options[:size] || 1_000).to_i
                            cursor = (options[:cursor] || [])
                        
                            response =
                        Severity: Minor
                        Found in app/models/event.rb - About 1 hr to fix

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

                            def self.subj_id_check(options = {})
                              size = (options[:size] || 1_000).to_i
                              cursor = [options[:from_id], options[:until_id]]
                          
                              response =
                          Severity: Minor
                          Found in app/models/event.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 loop_through_events has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                          Open

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

                            def self.update_crossref(options = {})
                              size = (options[:size] || 1_000).to_i
                              cursor = (options[:cursor] || [])
                          
                              response =
                          Severity: Minor
                          Found in app/models/event.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 modify_nested_objects has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                          Wontfix

                            def self.modify_nested_objects(options = {})
                              size = (options[:size] || 1_000).to_i
                              cursor = [options[:from_id], options[:until_id]]
                          
                              response = Event.query(nil, page: { size: 1, cursor: [] })
                          Severity: Minor
                          Found in app/models/event.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 update_registrant has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def self.update_registrant(options = {})
                              size = (options[:size] || 1_000).to_i
                              cursor = (options[:cursor] || [])
                              # ra = options[:ra] || "crossref"
                              source_id = options[:source_id] || "datacite-crossref,crossref"
                          Severity: Minor
                          Found in app/models/event.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 update_datacite_orcid_auto_update has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def self.update_datacite_orcid_auto_update(options = {})
                              size = (options[:size] || 1_000).to_i
                              cursor = (options[:cursor] || []).to_i
                          
                              response =
                          Severity: Minor
                          Found in app/models/event.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 update_datacite_ra has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def self.update_datacite_ra(options = {})
                              size = (options[:size] || 1_000).to_i
                              cursor = (options[:cursor] || [])
                              ra = options[:ra] || "crossref"
                              source_id = "datacite-#{ra}"
                          Severity: Minor
                          Found in app/models/event.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 dois_to_import has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def dois_to_import
                              [doi_from_url(subj_id), doi_from_url(obj_id)].compact.reduce(
                                [],
                              ) do |sum, d|
                                prefix = d.split("/", 2).first
                          Severity: Minor
                          Found in app/models/event.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 set_defaults has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def set_defaults
                              self.uuid = SecureRandom.uuid if uuid.blank?
                              self.subj_id = normalize_doi(subj_id) || subj_id
                              self.obj_id = normalize_doi(obj_id) || obj_id
                          
                          
                          Severity: Minor
                          Found in app/models/event.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

                              Event.where(id: id..(id + 499)).find_in_batches(
                                batch_size: 500,
                              ) do |events|
                                response =
                                  Event.__elasticsearch__.client.bulk index: index,
                          Severity: Major
                          Found in app/models/event.rb and 1 other location - About 2 hrs to fix
                          app/models/activity.rb on lines 102..128

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

                          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

                              indexes :subj,
                                      type: :object,
                                      properties: {
                                        type: { type: :keyword },
                                        id: { type: :keyword },
                          Severity: Minor
                          Found in app/models/event.rb and 1 other location - About 45 mins to fix
                          app/models/event.rb on lines 174..189

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

                          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

                              indexes :obj,
                                      type: :object,
                                      properties: {
                                        type: { type: :keyword },
                                        id: { type: :keyword },
                          Severity: Minor
                          Found in app/models/event.rb and 1 other location - About 45 mins to fix
                          app/models/event.rb on lines 159..174

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

                          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 3 locations. Consider refactoring.
                          Open

                                relation_types: {
                                  terms: { field: "relation_type_id", size: 10, min_doc_count: 1 },
                                  aggs: {
                                    year_month: {
                                      date_histogram: {
                          Severity: Minor
                          Found in app/models/event.rb and 2 other locations - About 35 mins to fix
                          app/models/event.rb on lines 288..301
                          app/models/event.rb on lines 303..316

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

                          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 3 locations. Consider refactoring.
                          Open

                                citation_types: {
                                  terms: { field: "citation_type", size: 10, min_doc_count: 1 },
                                  aggs: {
                                    year_month: {
                                      date_histogram: {
                          Severity: Minor
                          Found in app/models/event.rb and 2 other locations - About 35 mins to fix
                          app/models/event.rb on lines 288..301
                          app/models/event.rb on lines 318..331

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

                          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 3 locations. Consider refactoring.
                          Open

                                registrants: {
                                  terms: { field: "registrant_id", size: 10, min_doc_count: 1 },
                                  aggs: {
                                    year: {
                                      date_histogram: {
                          Severity: Minor
                          Found in app/models/event.rb and 2 other locations - About 35 mins to fix
                          app/models/event.rb on lines 303..316
                          app/models/event.rb on lines 318..331

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

                          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