genome/dgi-db

View on GitHub
lib/utils/database.rb

Summary

Maintainability
F
3 days
Test Coverage

Method cleanup_whitespaces has 146 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def self.cleanup_whitespaces
      DataModel::InteractionClaimType.where("type LIKE ' %' or type LIKE '% '").all.each do |t|
        t.value = t.value.strip
        t.save!
      end
Severity: Major
Found in lib/utils/database.rb - About 5 hrs to fix

    File database.rb has 380 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Utils
      module Database
    
        def self.delete_genes
          sql = <<-SQL
    Severity: Minor
    Found in lib/utils/database.rb - About 5 hrs to fix

      Method cleanup_whitespaces has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.cleanup_whitespaces
            DataModel::InteractionClaimType.where("type LIKE ' %' or type LIKE '% '").all.each do |t|
              t.value = t.value.strip
              t.save!
            end
      Severity: Minor
      Found in lib/utils/database.rb - About 5 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 destroy_na has 100 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def self.destroy_na
            sql = <<-SQL
              delete from drug_claim_types_drug_claims d
              where
              d.drug_claim_id in
      Severity: Major
      Found in lib/utils/database.rb - About 4 hrs to fix

        Method delete_source has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def self.delete_source(source_db_name)
              source_id = DataModel::Source.where('lower(sources.source_db_name) = ?',
                source_db_name.downcase).pluck(:id).first
        
              if source_id
        Severity: Minor
        Found in lib/utils/database.rb - About 1 hr to fix

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

                  c.interaction_claims.each do |interaction|
                    clean_interaction = DataModel::InteractionClaim.where(gene_claim_id: interaction.gene_claim_id, drug_claim_id: clean_claim.id, source_id: interaction.source_id).first_or_create
                    interaction.interaction_claim_attributes.each do |attribute|
                      DataModel::InteractionClaimAttribute.where(name: attribute.name, value: attribute.value, interaction_claim_id: clean_interaction.id).first_or_create
                      attribute.delete
          Severity: Major
          Found in lib/utils/database.rb and 1 other location - About 1 hr to fix
          lib/utils/database.rb on lines 353..363

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

          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

                  c.interaction_claims.each do |interaction|
                    clean_interaction = DataModel::InteractionClaim.where(drug_claim_id: interaction.drug_claim_id, gene_claim_id: clean_claim.id, source_id: interaction.source_id).first_or_create
                    interaction.interaction_claim_attributes.each do |attribute|
                      DataModel::InteractionClaimAttribute.where(name: attribute.name, value: attribute.value, interaction_claim_id: clean_interaction.id).first_or_create
                      attribute.delete
          Severity: Major
          Found in lib/utils/database.rb and 1 other location - About 1 hr to fix
          lib/utils/database.rb on lines 414..424

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

          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

                DataModel::GeneAttribute.where("name LIKE ' %' or name LIKE '% '").all.each do |a|
                  clean_attribute = DataModel::GeneAttribute.where(name: a.name.strip, value: a.value.strip, gene_id: a.gene_id).first_or_create
                  a.sources.each do |source|
                    clean_attribute.sources << source unless clean_attribute.sources.include? source
                    a.sources.delete(source)
          Severity: Minor
          Found in lib/utils/database.rb and 1 other location - About 1 hr to fix
          lib/utils/database.rb on lines 334..340

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

          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

                DataModel::GeneAttribute.where("value LIKE ' %' or value LIKE '% '").all.each do |a|
                  clean_attribute = DataModel::GeneAttribute.where(name: a.name.strip, value: a.value.strip, gene_id: a.gene_id).first_or_create
                  a.sources.each do |source|
                    clean_attribute.sources << source unless clean_attribute.sources.include? source
                    a.sources.delete(source)
          Severity: Minor
          Found in lib/utils/database.rb and 1 other location - About 1 hr to fix
          lib/utils/database.rb on lines 326..332

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

          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