datacite/lupo

View on GitHub
app/controllers/providers_controller.rb

Summary

Maintainability
F
3 days
Test Coverage
F
14%

Method index has 197 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/providers_controller.rb - About 7 hrs to fix

    File providers_controller.rb has 445 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class ProvidersController < ApplicationController
      include ActionController::MimeResponds
      include Countable
    
      prepend_before_action :authenticate_user!
    Severity: Minor
    Found in app/controllers/providers_controller.rb - About 6 hrs to fix

      Method safe_params has 85 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/providers_controller.rb - About 3 hrs to fix

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

          def index
            sort =
              case params[:sort]
              when "relevance"
                { "_score" => { order: "desc" } }
        Severity: Minor
        Found in app/controllers/providers_controller.rb - About 3 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 has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def destroy
            if active_client_count(provider_id: @provider.symbol).positive?
              message = "Can't delete provider that has active clients."
              status = 400
              Rails.logger.warn message
        Severity: Minor
        Found in app/controllers/providers_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 7 locations. Consider refactoring.
        Open

            sort =
              case params[:sort]
              when "relevance"
                { "_score" => { order: "desc" } }
              when "name"
        Severity: Major
        Found in app/controllers/providers_controller.rb and 6 other locations - About 1 hr to fix
        app/controllers/clients_controller.rb on lines 12..25
        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/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

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

          def update
            if @provider.update(safe_params)
              options = {}
              options[:include] = @include
              options[:is_collection] = false
        Severity: Major
        Found in app/controllers/providers_controller.rb and 1 other location - About 1 hr to fix
        app/controllers/contacts_controller.rb on lines 143..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 48.

        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/providers_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/clients_controller.rb on lines 135..148
        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/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 @provider.update(is_active: nil, deleted_at: Time.zone.now)
              unless Rails.env.test?
                @provider.send_delete_email(responsible_id: current_user.uid)
              end
              head :no_content
        Severity: Minor
        Found in app/controllers/providers_controller.rb and 1 other location - About 35 mins to fix
        app/controllers/clients_controller.rb on lines 221..230

        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 5 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[contacts]
        Severity: Minor
        Found in app/controllers/providers_controller.rb and 4 other locations - About 20 mins to fix
        app/controllers/contacts_controller.rb on lines 183..189
        app/controllers/media_controller.rb on lines 136..142
        app/controllers/metadata_controller.rb on lines 131..137
        app/controllers/repositories_controller.rb on lines 323..329

        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

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

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

        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