rubygems/rubygems.org

View on GitHub

Showing 25 of 40 total issues

Method error_messages_for has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

  def error_messages_for(*params)
    options = params.extract_options!.symbolize_keys

    objects = Array.wrap(options.delete(:object) || params).map do |object|
      object = instance_variable_get("@#{object}") unless object.respond_to?(:to_model)
Severity: Minor
Found in app/helpers/dynamic_errors_helper.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

Class ApplicationController has 29 methods (exceeds 20 allowed). Consider refactoring.
Open

class ApplicationController < ActionController::Base
  include Clearance::Authentication
  include ApplicationMultifactorMethods
  include TraceTagger

Severity: Minor
Found in app/controllers/application_controller.rb - About 3 hrs to fix

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

      def query
        from = Time.zone.today.midnight - 1.week
        to = Time.zone.now
    
        if range.present?
    Severity: Major
    Found in app/avo/cards/versions_metric.rb and 1 other location - About 1 hr to fix
    app/avo/cards/rubygems_metric.rb on lines 18..41

    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

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

      def query
        from = Time.zone.today.midnight - 1.week
        to = Time.zone.now
    
        if range.present?
    Severity: Major
    Found in app/avo/cards/rubygems_metric.rb and 1 other location - About 1 hr to fix
    app/avo/cards/versions_metric.rb on lines 19..42

    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

    Method search_definition has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def search_definition(for_api: false) # rubocop:disable Metrics/MethodLength
        query_str = @query
        source_array = for_api ? api_source : ui_source
    
        OpenSearch::DSL::Search.search do
    Severity: Minor
    Found in lib/elastic_searcher.rb - About 1 hr to fix

      Method error_messages_for has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def error_messages_for(*params)
          options = params.extract_options!.symbolize_keys
      
          objects = Array.wrap(options.delete(:object) || params).map do |object|
            object = instance_variable_get("@#{object}") unless object.respond_to?(:to_model)
      Severity: Minor
      Found in app/helpers/dynamic_errors_helper.rb - About 1 hr to fix

        Method search_data has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def search_data # rubocop:disable Metrics/MethodLength
              if (latest_version = most_recent_version)
                deps = latest_version.dependencies.to_a
                versioned_links = links(latest_version)
              end
        Severity: Minor
        Found in app/models/concerns/rubygem_searchable.rb - About 1 hr to fix

          Method compute_compact_index_info has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

            def compute_compact_index_info
              requirements_and_dependencies.map do |r|
                deps = []
                if r[DEPENDENCY_REQUIREMENTS_INDEX]
                  reqs = r[DEPENDENCY_REQUIREMENTS_INDEX].split("@")
          Severity: Minor
          Found in app/models/gem_info.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 check_mfa has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

            def check_mfa(user)
              if user&.mfa_gem_signin_authorized?(otp)
                return render_mfa_setup_required_error if user.mfa_required_not_yet_enabled?
                return render_mfa_strong_level_required_error if user.mfa_required_weak_level_enabled?
          
          
          Severity: Minor
          Found in app/controllers/api/v1/api_keys_controller.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 process has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

            def process(version)
              logger.tagged(version_id: version.id, name: version.rubygem.name, number: version.number, platform: version.platform) do
                logger.info "Updating spec_sha256 for #{version.full_name}"
          
                spec_path = "quick/Marshal.4.8/#{version.full_name}.gemspec.rz"
          Severity: Minor
          Found in app/tasks/maintenance/backfill_spec_sha256_task.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

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

            field :trace_id, as: :text, format_using: proc {
              if value.present?
                link_to(
                  view == :index ? "🔗" : value,
                  "https://app.datadoghq.com/logs?query=#{{
          Severity: Minor
          Found in app/avo/resources/events_rubygem_event_resource.rb and 1 other location - About 1 hr to fix
          app/avo/resources/events_user_event_resource.rb on lines 9..23

          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

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

            field :trace_id, as: :text, format_using: proc {
              if value.present?
                link_to(
                  view == :index ? "🔗" : value,
                  "https://app.datadoghq.com/logs?query=#{{
          Severity: Minor
          Found in app/avo/resources/events_user_event_resource.rb and 1 other location - About 1 hr to fix
          app/avo/resources/events_rubygem_event_resource.rb on lines 9..23

          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

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

            def validate_gem_and_version
              if !@rubygem.hosted?
                render plain: response_with_mfa_warning(t(:this_rubygem_could_not_be_found)),
                       status: :not_found
              elsif !@rubygem.owned_by?(@api_key.user)
          Severity: Minor
          Found in app/controllers/api/v1/deletions_controller.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 show has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def show
              return unless params[:query].is_a?(String)
              @error_msg, @gems = ElasticSearcher.new(params[:query], page: @page).search
          
              return unless @gems
          Severity: Minor
          Found in app/controllers/searches_controller.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 valid_if_admin has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def valid_if_admin
              return unless is_admin
          
              errors.add(:is_admin, "missing oauth token") if oauth_token.blank?
              errors.add(:is_admin, "missing info data") if info_data.blank?
          Severity: Minor
          Found in app/models/admin/github_user.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 revoke has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def revoke
              key_id = request.headers.fetch("GITHUB-PUBLIC-KEY-IDENTIFIER", "")
              signature = request.headers.fetch("GITHUB-PUBLIC-KEY-SIGNATURE", "")
          
              return render plain: "Missing GitHub Signature", status: :unauthorized if key_id.blank? || signature.blank?
          Severity: Minor
          Found in app/controllers/api/v1/github_secret_scanning_controller.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 create has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def create
              return render_api_key_forbidden unless @api_key.can_add_owner?
          
              owner = User.find_by_name(email_param)
              if owner
          Severity: Minor
          Found in app/controllers/api/v1/owners_controller.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 destroy has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def destroy
              return render_api_key_forbidden unless @api_key.can_remove_owner?
          
              owner = @rubygem.owners_including_unconfirmed.find_by_name(email_param)
              if owner
          Severity: Minor
          Found in app/controllers/api/v1/owners_controller.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 query has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def query
              from = Time.zone.today.midnight - 1.week
              to = Time.zone.now
          
              if range.present?
          Severity: Minor
          Found in app/avo/cards/versions_metric.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 query has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def query
              from = Time.zone.today.midnight - 1.week
              to = Time.zone.now
          
              if range.present?
          Severity: Minor
          Found in app/avo/cards/rubygems_metric.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

          Severity
          Category
          Status
          Source
          Language