Showing 29 of 29 total issues

Class Base has 27 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Base

    attr_reader :klass, :state_machine

    def initialize(klass, name, state_machine, options={}, &block)
Severity: Minor
Found in lib/aasm/base.rb - About 3 hrs to fix

    Method _fire has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def _fire(obj, options={}, to_state=::AASM::NO_VALUE, *args)
          result = options[:test_only] ? false : nil
          clear_failed_callbacks
          transitions = @transitions.select { |t| t.from == obj.aasm(state_machine.name).current_state || t.from == nil}
          return result if transitions.size == 0
    Severity: Minor
    Found in lib/aasm/core/event.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 aasm_fired has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

      def aasm_fired(state_machine_name, event, old_state, new_state_name, options, *args)
        persist = options[:persist]
    
        new_state = aasm(state_machine_name).state_object_for_name(new_state_name)
        callback_args = process_args(event, aasm(state_machine_name).current_state, *args)
    Severity: Minor
    Found in lib/aasm/aasm.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 aasm_fired has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def aasm_fired(state_machine_name, event, old_state, new_state_name, options, *args)
        persist = options[:persist]
    
        new_state = aasm(state_machine_name).state_object_for_name(new_state_name)
        callback_args = process_args(event, aasm(state_machine_name).current_state, *args)
    Severity: Minor
    Found in lib/aasm/aasm.rb - About 1 hr to fix

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

          def states(options={}, *args)
            if options.has_key?(:permitted)
              selected_events = events({:permitted => options[:permitted]}, *args)
              # An array of arrays. Each inner array represents the transitions that
              # transition from the current state for an event
      Severity: Minor
      Found in lib/aasm/instance_base.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

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      module Mongoid
        module Generators
          class AASMGenerator < Rails::Generators::NamedBase
            include AASM::Generators::OrmHelpers
            namespace "mongoid:aasm"
      Severity: Major
      Found in lib/generators/mongoid/aasm_generator.rb and 1 other location - About 1 hr to fix
      lib/generators/nobrainer/aasm_generator.rb on lines 4..24

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 52.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      module NoBrainer
        module Generators
          class AASMGenerator < Rails::Generators::NamedBase
            include AASM::Generators::OrmHelpers
            namespace 'nobrainer:aasm'
      Severity: Major
      Found in lib/generators/nobrainer/aasm_generator.rb and 1 other location - About 1 hr to fix
      lib/generators/mongoid/aasm_generator.rb on lines 4..24

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 52.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

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

          def aasm(*args, &block)
            if args[0].is_a?(Symbol) || args[0].is_a?(String)
              # using custom name
              state_machine_name = args[0].to_sym
              options = args[1] || {}
      Severity: Minor
      Found in lib/aasm/aasm.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 state has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def state(*args)
            names, options = interpret_state_args(args)
            names.each do |name|
              @state_machine.add_state(name, klass, options)
      
      
      Severity: Minor
      Found in lib/aasm/base.rb - About 55 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 load_persistence has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

            def load_persistence(base)
              # Use a fancier auto-loading thingy, perhaps.  When there are more persistence engines.
              hierarchy = base.ancestors.map {|klass| klass.to_s}
      
              if hierarchy.include?("ActiveRecord::Base")
      Severity: Minor
      Found in lib/aasm/persistence.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 aasm_ensure_initial_state has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

              def aasm_ensure_initial_state
                AASM::StateMachineStore.fetch(self.class, true).machine_names.each do |state_machine_name|
                  attribute_name = self.class.aasm(state_machine_name).attribute_name.to_s
                  # Do not load initial state when object attributes are not loaded,
                  # mongoid has_many relationship does not load child object attributes when
      Severity: Minor
      Found in lib/aasm/persistence/mongoid_persistence.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 register has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def register(name, machine, force = false)
            raise "Cannot use #{name.inspect} for machine name" unless name.is_a?(Symbol) or name.is_a?(String)
            raise "Cannot use #{machine.inspect} as a machine" unless machine.is_a?(AASM::StateMachine)
      
            if force
      Severity: Minor
      Found in lib/aasm/state_machine_store.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 aasm_fired has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        def aasm_fired(state_machine_name, event, old_state, new_state_name, options, *args)
      Severity: Minor
      Found in lib/aasm/aasm.rb - About 45 mins to fix

        Method initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def initialize(klass, name, state_machine, options={}, &block)
        Severity: Minor
        Found in lib/aasm/base.rb - About 35 mins to fix

          Method aasm_fire_event has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

            def aasm_fire_event(state_machine_name, event_name, options, *args, &block)
          Severity: Minor
          Found in lib/aasm/aasm.rb - About 35 mins to fix

            Method aasm_fire_event has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                  def aasm_fire_event(state_machine_name, name, options, *args, &block)
            Severity: Minor
            Found in lib/aasm/persistence/orm.rb - About 35 mins to fix

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                def assert_transitions_from(object, from_state, *args)
                  options = args.first
                  options[:on] ||= :default
                  assert _transitions_from?(object, from_state, args, options),
                        "Expected transition state to :#{options[:to]} from :#{from_state} on event :#{options[:on_event]}, (on :#{options[:on]})"
              Severity: Minor
              Found in lib/aasm/minitest/transition_from.rb and 1 other location - About 35 mins to fix
              lib/aasm/minitest/transition_from.rb on lines 9..13

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 35.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Method aasm_fire_event has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                    def aasm_fire_event(state_machine_name, name, options, *args, &block)
                      return super unless aasm_supports_transactions? && options[:persist]
              
                      event = self.class.aasm(state_machine_name).state_machine.events[name]
                      event.fire_callbacks(:before_transaction, self, *args)
              Severity: Minor
              Found in lib/aasm/persistence/orm.rb - About 35 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 aasm_fire_event has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def aasm_fire_event(state_machine_name, event_name, options, *args, &block)
                  event = self.class.aasm(state_machine_name).state_machine.events[event_name]
                  begin
                    old_state = aasm(state_machine_name).state_object_for_name(aasm(state_machine_name).current_state)
              
              
              Severity: Minor
              Found in lib/aasm/aasm.rb - About 35 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

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                def refute_transitions_from(object, from_state, *args)
                  options = args.first
                  options[:on] ||= :default
                  refute _transitions_from?(object, from_state, args, options),
                        "Expected transition state to :#{options[:to]} from :#{from_state} on event :#{options[:on_event]}, (on :#{options[:on]})"
              Severity: Minor
              Found in lib/aasm/minitest/transition_from.rb and 1 other location - About 35 mins to fix
              lib/aasm/minitest/transition_from.rb on lines 2..6

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 35.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Severity
              Category
              Status
              Source
              Language