pboling/activerecord-transactionable

View on GitHub

Showing 9 of 9 total issues

Method run_block_with_retry has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

      def run_block_with_retry(object, local_context, transaction_open, retriable_errors, reraisable_errors, already_been_added_to_self, needing_added_to_self, num_retry_attempts)
        attempt = 0
        re_try = false
        begin
          attempt += 1
Severity: Minor
Found in lib/activerecord/transactionable.rb - About 3 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

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

      def error_handler_inside_transaction(transaction_open:, object: nil, **args, &block)
        rescued_errors = Array(args[:rescued_errors])
        prepared_errors = Array(args[:prepared_errors])
        retriable_errors = Array(args[:retriable_errors])
        reraisable_errors = Array(args[:reraisable_errors])
Severity: Major
Found in lib/activerecord/transactionable.rb and 1 other location - About 1 hr to fix
lib/activerecord/transactionable.rb on lines 146..159

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 66.

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

      def error_handler_outside_transaction(transaction_open:, object: nil, **args, &block)
        rescued_errors = Array(args[:outside_rescued_errors])
        prepared_errors = Array(args[:outside_prepared_errors])
        retriable_errors = Array(args[:outside_retriable_errors])
        reraisable_errors = Array(args[:outside_reraisable_errors])
Severity: Major
Found in lib/activerecord/transactionable.rb and 1 other location - About 1 hr to fix
lib/activerecord/transactionable.rb on lines 130..143

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 66.

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 run_block_with_retry has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def run_block_with_retry(object, local_context, transaction_open, retriable_errors, reraisable_errors, already_been_added_to_self, needing_added_to_self, num_retry_attempts)
        attempt = 0
        re_try = false
        begin
          attempt += 1
Severity: Minor
Found in lib/activerecord/transactionable.rb - About 1 hr to fix

    Method transaction_wrapper has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def transaction_wrapper(object: nil, **args)
            lock = args.delete(:lock)
            inside_args = extract_args(args, INSIDE_TRANSACTION_ERROR_HANDLERS)
            outside_args = extract_args(args, OUTSIDE_TRANSACTION_ERROR_HANDLERS)
            transaction_args = extract_args(args, TRANSACTION_METHOD_ARG_NAMES)
    Severity: Minor
    Found in lib/activerecord/transactionable.rb - About 1 hr to fix

      Method run_block_with_retry has 8 arguments (exceeds 4 allowed). Consider refactoring.
      Open

            def run_block_with_retry(object, local_context, transaction_open, retriable_errors, reraisable_errors, already_been_added_to_self, needing_added_to_self, num_retry_attempts)
      Severity: Major
      Found in lib/activerecord/transactionable.rb - About 1 hr to fix

        Method transaction_error_logger has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

              def transaction_error_logger(object:, error:, result:, attempt: nil, add_to: :base, additional_message: nil, **_opts)
                # Ruby arguments, like object, are passed by reference,
                #   so this update to errors will be available to the caller
                if object.nil?
                  # when a transaction wraps a bunch of CRUD actions,
        Severity: Minor
        Found in lib/activerecord/transactionable.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 transaction_wrapper has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

              def transaction_wrapper(object: nil, **args)
                lock = args.delete(:lock)
                inside_args = extract_args(args, INSIDE_TRANSACTION_ERROR_HANDLERS)
                outside_args = extract_args(args, OUTSIDE_TRANSACTION_ERROR_HANDLERS)
                transaction_args = extract_args(args, TRANSACTION_METHOD_ARG_NAMES)
        Severity: Minor
        Found in lib/activerecord/transactionable.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 run_inside_transaction_block has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def run_inside_transaction_block(transaction_args:, inside_args:, lock:, transaction_open:, object: nil, &block)
                if object
                  if lock
                    # NOTE: with_lock will reload object!
                    # Note: with_lock does not accept arguments like transaction does.
        Severity: Minor
        Found in lib/activerecord/transactionable.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

        Severity
        Category
        Status
        Source
        Language