openjaf/cenit

View on GitHub
app/models/ability.rb

Summary

Maintainability
D
2 days
Test Coverage

Method prepare has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring.
Open

    def self.prepare
      return self if @init_done
      @init_done = true

      actions = Setup::Models.all.reduce(Set.new) do |set, model|
Severity: Minor
Found in app/models/ability.rb - About 1 day 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 prepare has 108 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def self.prepare
      return self if @init_done
      @init_done = true

      actions = Setup::Models.all.reduce(Set.new) do |set, model|
Severity: Major
Found in app/models/ability.rb - About 4 hrs to fix

    File ability.rb has 256 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'cancan/model_adapters/mongoff_adapter'
    require 'setup/storage'
    
    class Ability
      include CanCan::Ability
    Severity: Minor
    Found in app/models/ability.rb - About 2 hrs to fix

      Method can? has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def can?(action, subject, *extra_args)
          return true if action == :digest
          if action == :json_edit
            subject.is_a?(Mongoff::Record) && !subject.is_a?(Mongoff::GridFs::File)
          elsif (action == :simple_cross && crossing_models.exclude?(subject.is_a?(Class) ? subject : subject.class)) ||
      Severity: Minor
      Found in app/models/ability.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 initialize has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def initialize(user)
          @deferred_abilities = []
      
          deferred_abilities <<
            if (@user = user)
      Severity: Minor
      Found in app/models/ability.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 initialize has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def initialize(user)
          @deferred_abilities = []
      
          deferred_abilities <<
            if (@user = user)
      Severity: Minor
      Found in app/models/ability.rb - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

            elsif (action == :simple_cross && crossing_models.exclude?(subject.is_a?(Class) ? subject : subject.class)) ||
              (subject == ScriptExecution && (user.nil? || !user.super_admin?))
              false
            else
              super || deferred_abilities.any? { |ability| ability.can?(action, subject, *extra_args) }
        Severity: Major
        Found in app/models/ability.rb - About 40 mins to fix

          There are no issues that match your filters.

          Category
          Status