ManageIQ/miq_bot

View on GitHub
app/models/repo.rb

Summary

Maintainability
B
5 hrs
Test Coverage

Class Repo has 24 methods (exceeds 20 allowed). Consider refactoring.
Open

class Repo < ActiveRecord::Base
  BASE_PATH = Rails.root.join("repos")

  has_many :branches, :dependent => :destroy

Severity: Minor
Found in app/models/repo.rb - About 2 hrs to fix

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

      def synchronize_pr_branches(expected)
        raise "repo cannot not have PR branches" unless can_have_prs?
    
        git_fetch # TODO: Let's get rid of this!
    
    
    Severity: Minor
    Found in app/models/repo.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 synchronize_pr_branches has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def synchronize_pr_branches(expected)
        raise "repo cannot not have PR branches" unless can_have_prs?
    
        git_fetch # TODO: Let's get rid of this!
    
    
    Severity: Minor
    Found in app/models/repo.rb - About 1 hr to fix

      Do not suppress exceptions.
      Open

        rescue Errno::ENOENT
      Severity: Minor
      Found in app/models/repo.rb by rubocop

      Checks for rescue blocks with no body.

      Example:

      # bad
      def some_method
        do_something
      rescue
      end
      
      # bad
      begin
        do_something
      rescue
      end
      
      # good
      def some_method
        do_something
      rescue
        handle_exception
      end
      
      # good
      begin
        do_something
      rescue
        handle_exception
      end

      Example: AllowComments: true (default)

      # good
      def some_method
        do_something
      rescue
        # do nothing
      end
      
      # good
      begin
        do_something
      rescue
        # do nothing
      end

      Example: AllowComments: false

      # bad
      def some_method
        do_something
      rescue
        # do nothing
      end
      
      # bad
      begin
        do_something
      rescue
        # do nothing
      end

      Example: AllowNil: true (default)

      # good
      def some_method
        do_something
      rescue
        nil
      end
      
      # good
      begin
        do_something
      rescue
        # do nothing
      end
      
      # good
      do_something rescue nil

      Example: AllowNil: false

      # bad
      def some_method
        do_something
      rescue
        nil
      end
      
      # bad
      begin
        do_something
      rescue
        nil
      end
      
      # bad
      do_something rescue nil

      There are no issues that match your filters.

      Category
      Status