librariesio/libraries.io

View on GitHub
app/models/repository.rb

Summary

Maintainability
D
1 day
Test Coverage

Method create_from_hash has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

  def self.create_from_hash(repo_hash)
    return unless repo_hash
    repo_hash = repo_hash.to_hash.with_indifferent_access
    ActiveRecord::Base.transaction do
      g = Repository.where(host_type: (repo_hash[:host_type] || 'GitHub')).find_by(uuid: repo_hash[:id])
Severity: Minor
Found in app/models/repository.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 Repository has 36 methods (exceeds 20 allowed). Consider refactoring.
Open

class Repository < ApplicationRecord
  include RepoSearch
  include Status
  include RepoManifests
  include RepositorySourceRank
Severity: Minor
Found in app/models/repository.rb - About 4 hrs to fix

    File repository.rb has 278 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class Repository < ApplicationRecord
      include RepoSearch
      include Status
      include RepoManifests
      include RepositorySourceRank
    Severity: Minor
    Found in app/models/repository.rb - About 2 hrs to fix

      Method check_status has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.check_status(host_type, repo_full_name, removed = false)
          domain = RepositoryHost::Base.domain(host_type)
          response = Typhoeus.head("#{domain}/#{repo_full_name}")
      
          if response.response_code == 404
      Severity: Minor
      Found in app/models/repository.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 update_all_info has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def update_all_info(token = nil)
          token ||= AuthToken.token if host_type == 'GitHub'
          check_status
          return if status == 'Removed'
          update_from_repository(token)
      Severity: Minor
      Found in app/models/repository.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 normalize_license_and_language has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def normalize_license_and_language
          self.language = Linguist::Language[self.language].to_s
          self.language = nil if self.language.blank?
          return if license.blank?
          if license.downcase == 'other'
      Severity: Minor
      Found in app/models/repository.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

      There are no issues that match your filters.

      Category
      Status