expertiza/expertiza

View on GitHub
app/models/role.rb

Summary

Maintainability
A
3 hrs
Test Coverage
D
64%

Class has too many lines. [120/100]
Open

class Role < ApplicationRecord
  belongs_to :parent, class_name: 'Role', inverse_of: false
  has_many :users, inverse_of: false, dependent: :nullify

  serialize :cache
Severity: Minor
Found in app/models/role.rb by rubocop

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [18/10]
Open

  def get_parents
    parents = []
    seen = {}

    current = id
Severity: Minor
Found in app/models/role.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Class Role has 22 methods (exceeds 20 allowed). Consider refactoring.
Open

class Role < ApplicationRecord
  belongs_to :parent, class_name: 'Role', inverse_of: false
  has_many :users, inverse_of: false, dependent: :nullify

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

    Method has too many lines. [11/10]
    Open

      def get_available_roles
        ids = []
    
        current = parent_id
        while current
    Severity: Minor
    Found in app/models/role.rb by rubocop

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

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

      def get_available_roles
        ids = []
    
        current = parent_id
        while current
    Severity: Minor
    Found in app/models/role.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 get_parents has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def get_parents
        parents = []
        seen = {}
    
        current = id
    Severity: Minor
    Found in app/models/role.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

    Do not prefix reader method names with get_.
    Open

      def get_parents
    Severity: Minor
    Found in app/models/role.rb by rubocop

    This cop makes sure that accessor methods are named properly.

    Example:

    # bad
    def set_attribute(value)
    end
    
    # good
    def attribute=(value)
    end
    
    # bad
    def get_attribute
    end
    
    # good
    def attribute
    end

    Rename has_all_privileges_of? to all_privileges_of?.
    Open

      def has_all_privileges_of?(target_role)
    Severity: Minor
    Found in app/models/role.rb by rubocop

    This cop makes sure that predicates are named properly.

    Example:

    # bad
    def is_even?(value)
    end
    
    # good
    def even?(value)
    end
    
    # bad
    def has_value?
    end
    
    # good
    def value?
    end

    Missing top-level class documentation comment.
    Open

    class Role < ApplicationRecord
    Severity: Minor
    Found in app/models/role.rb by rubocop

    This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

    The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

    Example:

    # bad
    class Person
      # ...
    end
    
    # good
    # Description/Explanation of Person class
    class Person
      # ...
    end

    Do not prefix reader method names with get_.
    Open

      def get_available_roles
    Severity: Minor
    Found in app/models/role.rb by rubocop

    This cop makes sure that accessor methods are named properly.

    Example:

    # bad
    def set_attribute(value)
    end
    
    # good
    def attribute=(value)
    end
    
    # bad
    def get_attribute
    end
    
    # good
    def attribute
    end

    There are no issues that match your filters.

    Category
    Status