rubygems/rubygems.org

View on GitHub

Showing 22 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 28 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

    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

          Method view_template has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

            def view_template
              self.title = t(".title")
          
              return if not_configured
          
          
          Severity: Minor
          Found in app/views/oidc/api_key_roles/github_actions_workflow_view.rb - About 55 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 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 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 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 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

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

          Avoid too many return statements within this method.
          Open

              return false if suggestions["suggest_name"][0]["options"].empty?
          Severity: Major
          Found in app/helpers/searches_helper.rb - About 30 mins to fix

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

              def es_suggestions(gems)
                return false if gems.size >= 1
                return false unless gems.respond_to?(:response)
                suggestions = gems.response["suggest"]
                return false if suggestions.blank?
            Severity: Minor
            Found in app/helpers/searches_helper.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

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

              def index
                return unless stale?(@rubygem)
                cache_expiry_headers
                set_surrogate_key "gem/#{@rubygem.name}"
            
            
            Severity: Minor
            Found in app/controllers/api/v2/contents_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

            Severity
            Category
            Status
            Source
            Language