datacite/lupo

View on GitHub
app/controllers/clients_controller.rb

Summary

Maintainability
D
2 days
Test Coverage
F
15%

Method index has 128 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def index
    sort =
      case params[:sort]
      when "relevance"
        { "_score" => { order: "desc" } }
Severity: Major
Found in app/controllers/clients_controller.rb - About 5 hrs to fix

    File clients_controller.rb has 311 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class ClientsController < ApplicationController
      include Countable
    
      before_action :set_client, only: %i[show update destroy]
      before_action :authenticate_user!
    Severity: Minor
    Found in app/controllers/clients_controller.rb - About 3 hrs to fix

      Method index has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        def index
          sort =
            case params[:sort]
            when "relevance"
              { "_score" => { order: "desc" } }
      Severity: Minor
      Found in app/controllers/clients_controller.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 safe_params has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def safe_params
            if params[:data].blank?
              fail JSON::ParserError,
                   "You need to provide a payload following the JSONAPI spec"
            end
      Severity: Major
      Found in app/controllers/clients_controller.rb - About 2 hrs to fix

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

          def destroy
            if @client.dois.present?
              message = "Can't delete client that has DOIs."
              status = 400
              Rails.logger.warn message
        Severity: Minor
        Found in app/controllers/clients_controller.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

          def update
            options = {}
            options[:is_collection] = false
            options[:params] = { current_ability: current_ability, detail: true }
        
        
        Severity: Major
        Found in app/controllers/clients_controller.rb and 1 other location - About 1 hr to fix
        app/controllers/repositories_controller.rb on lines 221..244

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

        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 totals
            page = { size: 0, number: 1 }
            state =
              if current_user.present? && current_user.is_admin_or_staff? &&
                  params[:state].present?
        Severity: Major
        Found in app/controllers/clients_controller.rb and 1 other location - About 1 hr to fix
        app/controllers/repositories_controller.rb on lines 273..299

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

        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

          def create
            @client = Client.new(safe_params)
            authorize! :create, @client
        
            if @client.save
        Severity: Major
        Found in app/controllers/clients_controller.rb and 1 other location - About 1 hr to fix
        app/controllers/repositories_controller.rb on lines 199..218

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

        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

                    request.base_url + "/clients?" +
                      {
                        query: params[:query],
                        "provider-id" => params[:provider_id],
                        software: params[:software],
        Severity: Major
        Found in app/controllers/clients_controller.rb and 1 other location - About 1 hr to fix
        app/controllers/repositories_controller.rb on lines 105..118

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

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

            sort =
              case params[:sort]
              when "relevance"
                { "_score" => { order: "desc" } }
              when "name"
        Severity: Major
        Found in app/controllers/clients_controller.rb and 6 other locations - About 1 hr to fix
        app/controllers/contacts_controller.rb on lines 15..28
        app/controllers/data_centers_controller.rb on lines 8..21
        app/controllers/members_controller.rb on lines 7..20
        app/controllers/organizations_controller.rb on lines 10..23
        app/controllers/providers_controller.rb on lines 13..26
        app/controllers/repositories_controller.rb on lines 16..29

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

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

            rescue Elasticsearch::Transport::Transport::Errors::BadRequest => e
              Raven.capture_exception(e)
        
              message =
                JSON.parse(e.message[6..-1]).to_h.dig(
        Severity: Major
        Found in app/controllers/clients_controller.rb and 11 other locations - About 35 mins to fix
        app/controllers/activities_controller.rb on lines 122..135
        app/controllers/client_prefixes_controller.rb on lines 97..110
        app/controllers/contacts_controller.rb on lines 94..107
        app/controllers/data_centers_controller.rb on lines 94..107
        app/controllers/members_controller.rb on lines 106..119
        app/controllers/organizations_controller.rb on lines 183..196
        app/controllers/prefixes_controller.rb on lines 106..119
        app/controllers/provider_prefixes_controller.rb on lines 97..113
        app/controllers/providers_controller.rb on lines 205..218
        app/controllers/repositories_controller.rb on lines 160..173
        app/controllers/repository_prefixes_controller.rb on lines 98..111

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

        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

            elsif @client.update(is_active: nil, deleted_at: Time.zone.now)
              unless Rails.env.test?
                @client.send_delete_email(responsible_id: current_user.uid)
              end
              head :no_content
        Severity: Minor
        Found in app/controllers/clients_controller.rb and 1 other location - About 35 mins to fix
        app/controllers/providers_controller.rb on lines 299..308

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

            def set_include
              if params[:include].present?
                @include =
                  params[:include].split(",").map { |i| i.downcase.underscore.to_sym }
                @include = @include & %i[provider repository]
        Severity: Minor
        Found in app/controllers/clients_controller.rb and 3 other locations - About 25 mins to fix
        app/controllers/datacite_dois_controller.rb on lines 747..753
        app/controllers/events_controller.rb on lines 305..311
        app/controllers/old_events_controller.rb on lines 300..306

        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

          def show
            options = {}
            options[:include] = @include
            options[:is_collection] = false
            options[:params] = { current_ability: current_ability }
        Severity: Minor
        Found in app/controllers/clients_controller.rb and 1 other location - About 25 mins to fix
        app/controllers/contacts_controller.rb on lines 110..119

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

              if fields
                render(
                  json: ClientSerializer.new(@clients, options.merge(fields: fields)).serializable_hash.to_json,
                  status: :ok
                )
        Severity: Minor
        Found in app/controllers/clients_controller.rb and 2 other locations - About 20 mins to fix
        app/controllers/organizations_controller.rb on lines 115..124
        app/controllers/providers_controller.rb on lines 138..147

        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

          def stats
            meta = {
              dois:
                doi_count(
                  client_id:
        Severity: Minor
        Found in app/controllers/clients_controller.rb and 1 other location - About 15 mins to fix
        app/controllers/repositories_controller.rb on lines 301..315

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

        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