datacite/lupo

View on GitHub
app/models/client.rb

Summary

Maintainability
F
6 days
Test Coverage
F
40%

File client.rb has 882 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Client < ApplicationRecord
  SUBJECTS_JSON_SCHEMA = Rails.root.join("app", "models", "schemas", "client", "subjects.json")
  audited except: %i[
    system_email
    service_contact
Severity: Major
Found in app/models/client.rb - About 2 days to fix

    Class Client has 46 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Client < ApplicationRecord
      SUBJECTS_JSON_SCHEMA = Rails.root.join("app", "models", "schemas", "client", "subjects.json")
      audited except: %i[
        system_email
        service_contact
    Severity: Minor
    Found in app/models/client.rb - About 6 hrs to fix

      Method export_doi_counts has 76 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.export_doi_counts(query: nil)
          # Loop through all clients
          page = { size: 1_000, number: 1 }
          response = self.query(query, page: page)
          clients = response.results.to_a
      Severity: Major
      Found in app/models/client.rb - About 3 hrs to fix

        Method check_issn has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

            def check_issn
              Array.wrap(issn).each do |i|
                if !i.is_a?(Hash)
                  errors.add(:issn, "ISSN should be an object and not a string.")
                elsif i["issnl"].present?
        Severity: Minor
        Found in app/models/client.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 export_doi_counts has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.export_doi_counts(query: nil)
            # Loop through all clients
            page = { size: 1_000, number: 1 }
            response = self.query(query, page: page)
            clients = response.results.to_a
        Severity: Minor
        Found in app/models/client.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 set_defaults has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            def set_defaults
              self.domains = "*" if domains.blank?
              self.client_type = "repository" if client_type.blank?
              self.issn = {} if issn.blank? || client_type == "repository"
              self.certificate = [] if certificate.blank? || client_type == "periodical"
        Severity: Minor
        Found in app/models/client.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 as_indexed_json has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def as_indexed_json(options = {})
            {
              "id" => uid,
              "uid" => uid,
              "provider_id" => provider_id,
        Severity: Minor
        Found in app/models/client.rb - About 1 hr to fix

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

            def self.query_aggregations
              {
                years: {
                  date_histogram: {
                    field: "created",
          Severity: Minor
          Found in app/models/client.rb - About 1 hr to fix

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

              def transfer_prefixes(provider_target_id: nil)
                # These prefixes are used by multiple clients
                prefixes_to_keep = %w[10.4124 10.4225 10.4226 10.4227]
            
                # delete all associated prefixes
            Severity: Minor
            Found in app/models/client.rb - About 1 hr to fix

              Method to_jsonapi has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def to_jsonapi
                  response =
                    DataciteDoi.query(
                      nil,
                      client_id: uid, state: "findable,registered", page: { size: 0, number: 1 }, totals_agg: "client_export",
              Severity: Minor
              Found in app/models/client.rb - About 1 hr to fix

                Method to_jsonapi has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def to_jsonapi
                    response =
                      DataciteDoi.query(
                        nil,
                        client_id: uid, state: "findable,registered", page: { size: 0, number: 1 }, totals_agg: "client_export",
                Severity: Minor
                Found in app/models/client.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 assign_prefix has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Wontfix

                    def assign_prefix
                      available_prefix = get_prefix
                      if !available_prefix
                        errors.add(
                          :base,
                Severity: Minor
                Found in app/models/client.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 get_prefix has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Wontfix

                    def get_prefix
                      provider_prefix = (provider.present? && provider.provider_prefixes.present?) ? provider.provider_prefixes.select { |_provider_prefix| (_provider_prefix.state == "without-repository") }.first : nil
                      prefix = Prefix.all.count > 0 ? Prefix.where.missing(:client_prefixes).merge(Prefix.where.missing(:provider_prefixes)).first : nil
                
                      provider_prefix || prefix || nil
                Severity: Minor
                Found in app/models/client.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

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

                      indexes :provider,
                              type: :object,
                              properties: {
                                id: { type: :keyword },
                                uid: { type: :keyword },
                Severity: Major
                Found in app/models/client.rb and 1 other location - About 1 day to fix
                app/models/contact.rb on lines 76..219

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

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

                  def self.export(query: nil)
                    # Loop through all clients
                    i = 0
                    page = { size: 1_000, number: 1 }
                    response = self.query(query, include_deleted: true, page: page)
                Severity: Major
                Found in app/models/client.rb and 1 other location - About 2 hrs to fix
                app/models/contact.rb on lines 321..346

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

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

                  settings index: {
                    analysis: {
                      analyzer: {
                        string_lowercase: {
                          tokenizer: "keyword", filter: %w[lowercase ascii_folding]
                Severity: Minor
                Found in app/models/client.rb and 2 other locations - About 30 mins to fix
                app/models/contact.rb on lines 44..60
                app/models/provider.rb on lines 195..211

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

                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

                  def cumulative_years
                    if deleted_at && deleted_at.year > created_at.year
                      (created_at.year...deleted_at.year).to_a
                    elsif deleted_at
                      []
                Severity: Minor
                Found in app/models/client.rb and 1 other location - About 15 mins to fix
                app/models/provider.rb on lines 757..764

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

                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