state-machines/state_machines

View on GitHub

Showing 40 of 40 total issues

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 before has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

          def before(complete = true, index = 0, &block)
            unless @before_run
              while callback = machine.callbacks[:before][index]
                index += 1
      
      
      Severity: Minor
      Found in lib/state_machines/transition.rb - About 4 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 Transition has 30 methods (exceeds 20 allowed). Consider refactoring.
      Open

        class Transition
          # The object being transitioned
          attr_reader :object
      
          # The state machine for which this transition is defined
      Severity: Minor
      Found in lib/state_machines/transition.rb - About 3 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, **kwargs, &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 evaluate_method has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            def evaluate_method(object, method, *args, &block)
              case method
                when Symbol
                  klass = (class << object; self; end)
                  args = [] if (klass.method_defined?(method) || klass.private_method_defined?(method)) && object.method(method).arity == 0
        Severity: Minor
        Found in lib/state_machines/eval_helpers.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 run_methods has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            def run_methods(object, context = {}, index = 0, *args, &block)
              if type == :around
                current_method = @methods[index]
                if  current_method
                  yielded = false
        Severity: Minor
        Found in lib/state_machines/callback.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 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def initialize(machine, name, options = {}) #:nodoc:
              options.assert_valid_keys(:initial, :value, :cache, :if, :human_name)
        
              @machine = machine
              @name = name
        Severity: Minor
        Found in lib/state_machines/state.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 transition_for has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def transition_for(object, requirements = {})
              requirements.assert_valid_keys(:from, :to, :guard)
              requirements[:from] = machine.states.match!(object).name unless (custom_from_state = requirements.include?(:from))
        
              branches.each do |branch|
        Severity: Minor
        Found in lib/state_machines/event.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 perform has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def perform(&block)
              reset
        
              if valid?
                if use_event_attributes? && !block_given?
        Severity: Minor
        Found in lib/state_machines/transition_collection.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 attribute_transition_for has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def attribute_transition_for(object, invalidate = false)
              return unless machine.action
        
              # TODO, simplify
              machine.read(object, :event_transition) || if event_name = machine.read(object, :event)
        Severity: Minor
        Found in lib/state_machines/event_collection.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 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_states has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def initialize_states(object, options = {}, attributes = {})
              options.assert_valid_keys( :static, :dynamic, :to)
              options = {static: true, dynamic: true}.merge(options)
        
              result = yield if block_given?
        Severity: Minor
        Found in lib/state_machines/machine_collection.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 call has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def call(object, method, *args, &block)
              options = args.last.is_a?(Hash) ? args.pop : {}
              options = {method_name: method}.merge(options)
              state = machine.states.match!(object)
        
        
        Severity: Minor
        Found in lib/state_machines/state.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 run_callbacks has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def run_callbacks(index = 0)
              if index == 0
                # Clears any traces of the event attribute to prevent it from being
                # evaluated multiple times if actions are nested
                each do |transition|
        Severity: Minor
        Found in lib/state_machines/transition_collection.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 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def initialize(type, *args, &block)
              @type = type
              raise ArgumentError, 'Type must be :before, :after, :around, or :failure' unless [:before, :after, :around, :failure].include?(type)
        
              options = args.last.is_a?(Hash) ? args.pop : {}
        Severity: Minor
        Found in lib/state_machines/callback.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

          Severity
          Category
          Status
          Source
          Language