rubygems/rubygems.org

View on GitHub

Showing 22 of 22 total issues

Class Version has 55 methods (exceeds 20 allowed). Consider refactoring.
Open

class Version < ApplicationRecord
  belongs_to :rubygem, touch: true
  has_many :dependencies, -> { order('rubygems.name ASC').includes(:rubygem) }, dependent: :destroy, inverse_of: "version"
  has_one :gem_download, proc { |m| where(rubygem_id: m.rubygem_id) }, inverse_of: :version

Severity: Major
Found in app/models/version.rb - About 7 hrs to fix

    Class Rubygem has 51 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Rubygem < ApplicationRecord
      include Patterns
      include RubygemSearchable
    
      has_many :ownerships, dependent: :destroy
    Severity: Major
    Found in app/models/rubygem.rb - About 7 hrs to fix

      Class User has 36 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class User < ApplicationRecord
        include Clearance::User
        include Gravtastic
        is_gravtastic default: "retro"
      
      
      Severity: Minor
      Found in app/models/user.rb - About 4 hrs to fix

        File version.rb has 299 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        require 'digest/sha2'
        
        class Version < ApplicationRecord
          belongs_to :rubygem, touch: true
          has_many :dependencies, -> { order('rubygems.name ASC').includes(:rubygem) }, dependent: :destroy, inverse_of: "version"
        Severity: Minor
        Found in app/models/version.rb - About 3 hrs to fix

          File rubygem.rb has 258 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          class Rubygem < ApplicationRecord
            include Patterns
            include RubygemSearchable
          
            has_many :ownerships, dependent: :destroy
          Severity: Minor
          Found in app/models/rubygem.rb - About 2 hrs to fix

            Method elastic_search has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def self.elastic_search(query) # rubocop:disable Metrics/MethodLength
                  search_definition = Elasticsearch::DSL::Search.search do
                    query do
                      function_score do
                        query do
            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 payload has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def payload(version = versions.most_recent, protocol = Gemcutter::PROTOCOL, host_with_port = Gemcutter::HOST)
                  versioned_links = links(version)
                  deps = version.dependencies.to_a
                  {
                    'name'              => name,
              Severity: Minor
              Found in app/models/rubygem.rb - About 1 hr to fix

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

                  def unique_hook
                    if user && rubygem
                      if WebHook.exists?(user_id: user.id,
                                         rubygem_id: rubygem.id,
                                         url: url)
                Severity: Minor
                Found in app/models/web_hook.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 bulk_update has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def bulk_update(ary)
                      updates_by_version = {}
                      updates_by_gem = {}
                
                      ary.each do |full_name, count|
                Severity: Minor
                Found in app/models/gem_download.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: t(:this_rubygem_could_not_be_found),
                             status: :not_found
                    elsif !@rubygem.owned_by?(@api_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
                    authenticate_or_request_with_http_basic do |username, password|
                      user = User.authenticate(username, password)
                      otp = request.headers['HTTP_OTP']
                      if user&.mfa_api_authorized?(otp)
                Severity: Minor
                Found in app/controllers/api/v1/api_keys_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 call has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def call(env)
                    request = Rack::Request.new(env)
                
                    allowed_hosts = [Gemcutter::HOST, 'index.rubygems.org', 'fastly.rubygems.org', 'bundler.rubygems.org']
                
                
                Severity: Minor
                Found in app/middleware/redirector.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 find has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def find
                    name = spec.name.to_s
                
                    @rubygem = Rubygem.name_is(name).first || Rubygem.new(name: name)
                
                
                Severity: Minor
                Found in app/models/pusher.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 fire has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                  def fire(protocol, host_with_port, deploy_gem, version, delayed = true)
                Severity: Minor
                Found in app/models/web_hook.rb - About 35 mins to fix

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

                    def render_rubygems(versions)
                      rubygems = versions.includes(:dependencies, rubygem: :linkset).map do |version|
                        version.rubygem.payload(version)
                      end
                  
                  
                  Severity: Minor
                  Found in app/controllers/api/v1/timeframe_versions_controller.rb and 1 other location - About 35 mins to fix
                  app/controllers/api/v1/activities_controller.rb on lines 14..21

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

                  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 render_rubygems(versions)
                      rubygems = versions.includes(:dependencies, rubygem: :linkset).map do |version|
                        version.rubygem.payload(version)
                      end
                  
                  
                  Severity: Minor
                  Found in app/controllers/api/v1/activities_controller.rb and 1 other location - About 35 mins to fix
                  app/controllers/api/v1/timeframe_versions_controller.rb on lines 43..50

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

                  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

                  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 to_bundler has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def to_bundler
                        if number[0] == "0" || prerelease?
                          %(gem '#{rubygem.name}', '~> #{number}')
                        else
                          release = feature_release(number)
                    Severity: Minor
                    Found in app/models/version.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 search has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def self.search(query, elasticsearch: false, page: 1)
                          return [nil, legacy_search(query).page(page)] unless elasticsearch
                          result = elastic_search(query).page(page)
                          # Now we need to trigger the ES query so we can fallback if it fails
                          # rather than lazy loading from the view
                    Severity: Minor
                    Found in app/models/concerns/rubygem_searchable.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