state-machines/state_machines

View on GitHub
lib/state_machines/machine.rb

Summary

Maintainability
F
3 days
Test Coverage

Class Machine has 56 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Machine

    include EvalHelpers
    include MatcherHelpers

Severity: Major
Found in lib/state_machines/machine.rb - About 1 day to fix

    File machine.rb has 464 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module StateMachines
      # Represents a state machine for a particular attribute.  State machines
      # consist of states, events and a set of transitions that define how the
      # state changes after a particular event is fired.
      # 
    Severity: Minor
    Found in lib/state_machines/machine.rb - About 7 hrs to fix

      Method state has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          def state(*names, &block)
            options = names.last.is_a?(Hash) ? names.pop : {}
            options.assert_valid_keys(:value, :cache, :if, :human_name)
      
            # Store the context so that it can be used for / matched against any state
      Severity: Minor
      Found in lib/state_machines/machine.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 define_helper has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          def define_helper(scope, method, *args, &block)
            helper_module = @helper_modules.fetch(scope)
      
            if block_given?
              if !self.class.ignore_method_conflicts && conflicting_ancestor = owner_class_ancestor_has_method?(scope, method)
      Severity: Minor
      Found in lib/state_machines/machine.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 find_or_create has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

            def find_or_create(owner_class, *args, &block)
              options = args.last.is_a?(Hash) ? args.pop : {}
              name = args.first || :state
      
              # Find an existing machine
      Severity: Minor
      Found in lib/state_machines/machine.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 event has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def event(*names, &block)
            options = names.last.is_a?(Hash) ? names.pop : {}
            options.assert_valid_keys(:human_name)
      
            # Store the context so that it can be used for / matched against any event
      Severity: Minor
      Found in lib/state_machines/machine.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 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def initialize(owner_class, *args, &block)
            options = args.last.is_a?(Hash) ? args.pop : {}
            options.assert_valid_keys(:attribute, :initial, :initialize, :action, :plural, :namespace, :integration, :messages, :use_transactions)
      
            # Find an integration that matches this machine's owner class
      Severity: Minor
      Found in lib/state_machines/machine.rb - About 1 hr to fix

        Method initialize has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def initialize(owner_class, *args, &block)
              options = args.last.is_a?(Hash) ? args.pop : {}
              options.assert_valid_keys(:attribute, :initial, :initialize, :action, :plural, :namespace, :integration, :messages, :use_transactions)
        
              # Find an integration that matches this machine's owner class
        Severity: Minor
        Found in lib/state_machines/machine.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 owner_class_ancestor_has_method? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def owner_class_ancestor_has_method?(scope, method)
              return false unless owner_class_has_method?(scope, method)
        
              superclasses = owner_class.ancestors.select { |ancestor| ancestor.is_a?(Class) }[1..-1]
        
        
        Severity: Minor
        Found in lib/state_machines/machine.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 initialize_state has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def initialize_state(object, options = {})
              state = initial_state(object)
              if state && (options[:force] || initialize_state?(object))
                value = state.value
        
        
        Severity: Minor
        Found in lib/state_machines/machine.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 add_states has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def add_states(new_states)
              new_states.map do |new_state|
                # Check for other states that use a different class type for their name.
                # This typically prevents string / symbol misuse.
                if new_state && conflict = states.detect { |state| state.name && state.name.class != new_state.class }
        Severity: Minor
        Found in lib/state_machines/machine.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 define_event_helpers has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def define_event_helpers
              # Gets the events that are allowed to fire on the current object
              define_helper(:instance, attribute(:events)) do |machine, object, *args|
                machine.events.valid_for(object, *args).map { |event| event.name }
              end
        Severity: Minor
        Found in lib/state_machines/machine.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