npolar/api.npolar.no

View on GitHub
migration/dataset/dataset_doi.rb

Summary

Maintainability
F
3 days
Test Coverage

Method doi has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
Open

  def doi
    lambda {|d|

      doi = self.class.doi(d) # remember: a different doi may be registered for various reasons, see line #240
      dataset_is_updated_after_doi = false
Severity: Minor
Found in migration/dataset/dataset_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 hashi has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

  def hashi
    lambda {|d|

      d.title = d.title.strip
      begin
Severity: Minor
Found in migration/dataset/dataset_doi.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

File dataset_doi.rb has 308 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "date"
require "time"
require "json"
require "uri"
require "open-uri"
Severity: Minor
Found in migration/dataset/dataset_doi.rb - About 3 hrs to fix

    Method doi has 58 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def doi
        lambda {|d|
    
          doi = self.class.doi(d) # remember: a different doi may be registered for various reasons, see line #240
          dataset_is_updated_after_doi = false
    Severity: Major
    Found in migration/dataset/dataset_doi.rb - About 2 hrs to fix

      Method hashi has 50 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def hashi
          lambda {|d|
      
            d.title = d.title.strip
            begin
      Severity: Minor
      Found in migration/dataset/dataset_doi.rb - About 2 hrs to fix

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

          def data_link
            lambda {|d|
        
              if not d.links?
                d.links = []
        Severity: Minor
        Found in migration/dataset/dataset_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 email has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          def email
            lambda {|d|
        
              if not d.people?
                d.people = []
        Severity: Minor
        Found in migration/dataset/dataset_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 is_doi_metadata_changed? has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def is_doi_metadata_changed? d,k
            if not k.respond_to? :xpath
              log.warn "No existing kernel provided for #{d.id}"
              return true
            end
        Severity: Minor
        Found in migration/dataset/dataset_doi.rb - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

                if (d.doi.nil? or dataset_is_updated_after_doi) and is_released? d
          
                  if d.doi.nil?
                    m = self.class.dois.find {|doi| doi =~ /#{self.class.doi(d)}/}
                    if not m.nil?
          Severity: Major
          Found in migration/dataset/dataset_doi.rb - About 1 hr to fix

            Method request has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              def request(method, path, body="", headers={"Content-Type"=>"application/json"}, credentials=[ ENV["NPOLAR_API_USERNAME"], ENV["NPOLAR_API_PASSWORD"] ])
            Severity: Minor
            Found in migration/dataset/dataset_doi.rb - About 35 mins to fix

              Method is_doi_metadata_changed? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def is_doi_metadata_changed? d,k
                  if not k.respond_to? :xpath
                    log.warn "No existing kernel provided for #{d.id}"
                    return true
                  end
              Severity: Minor
              Found in migration/dataset/dataset_doi.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

                  if protect.any? and @@really
                    protect.each do |f|
                      uri = f["url"]+"?restricted=true"
                      log.info "Protecting #{f["filename"]}:\nPUT #{uri}"
                      r = request("PUT", uri, "")
              Severity: Minor
              Found in migration/dataset/dataset_doi.rb and 1 other location - About 35 mins to fix
              migration/dataset/dataset_doi.rb on lines 369..376

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

              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

                  if protected.any? and @@really
                    protected.each do |f|
                      uri = f["url"]+"?restricted=false"
                      log.info "Unlocking #{f["filename"]}:\nPUT #{uri}"
                      r = request("PUT", uri, "")
              Severity: Minor
              Found in migration/dataset/dataset_doi.rb and 1 other location - About 35 mins to fix
              migration/dataset/dataset_doi.rb on lines 357..364

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

              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

                            all_restricted = hashi["files"].reject {|f|
                              f["filename"] == "readme.txt" or f["filename"] == "md5sum.txt"
                            }.all? {|f|
                              f.key? "restricted" and f["restricted"] == true
                            }
              Severity: Minor
              Found in migration/dataset/dataset_doi.rb and 1 other location - About 25 mins to fix
              migration/dataset/dataset_doi.rb on lines 140..144

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

              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

                            restricted_files = hashi["files"].reject {|f|
                              f["filename"] == "readme.txt" or f["filename"] == "md5sum.txt"
                            }.select {|f|
                              f.key? "restricted" and f["restricted"] == true
                            }.map {|f| f["filename"] }
              Severity: Minor
              Found in migration/dataset/dataset_doi.rb and 1 other location - About 25 mins to fix
              migration/dataset/dataset_doi.rb on lines 154..158

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

              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

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

                  if not authors.any?
                    authors = (d.organisations||[]).select {|o| o.roles.include? "author"}.map {|o| "#{o.name} (#{o.id})" }
              Severity: Minor
              Found in migration/dataset/dataset_doi.rb and 1 other location - About 20 mins to fix
              migration/dataset/dataset_doi.rb on lines 404..405

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

              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

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

                  if not authors.any?
                    authors = (d.organisations||[]).select {|o| o.roles.include? "author"}.map {|o| "#{o.name} (#{o.id})" }
              Severity: Minor
              Found in migration/dataset/dataset_doi.rb and 1 other location - About 20 mins to fix
              migration/dataset/dataset_doi.rb on lines 332..333

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

              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