ryotarai/itamae

View on GitHub
lib/itamae/resource/base.rb

Summary

Maintainability
D
1 day
Test Coverage

File base.rb has 295 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'itamae'
require 'shellwords'
require 'hashie'

module Itamae
Severity: Minor
Found in lib/itamae/resource/base.rb - About 3 hrs to fix

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

        class Base
          class EvalContext
            attr_reader :attributes
            attr_reader :notifications
            attr_reader :subscriptions
    Severity: Minor
    Found in lib/itamae/resource/base.rb - About 3 hrs to fix

      Method run_action has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

            def run_action(action)
              runner.handler.event(:action, action: action) do
                original_attributes = @attributes # preserve and restore later
                @current_action = action
      
      
      Severity: Minor
      Found in lib/itamae/resource/base.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 has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

            def run(specific_action = nil)
              runner.handler.event(:resource, resource_type: resource_type, resource_name: resource_name) do
                Itamae.logger.debug "#{resource_type}[#{resource_name}]"
      
                Itamae.logger.with_indent_if(Itamae.logger.debug?) do
      Severity: Minor
      Found in lib/itamae/resource/base.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 process_attributes has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

            def process_attributes
              self.class.defined_attributes.each_pair do |key, details|
                @attributes[key] ||= @resource_name if details[:default_name]
                @attributes[key] = details[:default] if details.has_key?(:default) && !@attributes.has_key?(key)
      
      
      Severity: Minor
      Found in lib/itamae/resource/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

      Method run_action has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def run_action(action)
              runner.handler.event(:action, action: action) do
                original_attributes = @attributes # preserve and restore later
                @current_action = action
      
      
      Severity: Minor
      Found in lib/itamae/resource/base.rb - About 1 hr to fix

        Method notify has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

              def notify
                (notifications + recipe.children.subscribing(self)).each do |notification|
                  message = "Notifying #{notification.action} to #{notification.action_resource.resource_type} resource '#{notification.action_resource.resource_name}'"
        
                  if notification.delayed?
        Severity: Minor
        Found in lib/itamae/resource/base.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 show_differences has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def show_differences
                @current_attributes.each_pair do |key, current_value|
                  value = @attributes[key]
                  if current_value.nil? && value.nil?
                    # ignore
        Severity: Minor
        Found in lib/itamae/resource/base.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 method_missing has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

                def method_missing(method, *args, &block)
                  if @resource.class.defined_attributes[method]
                    if args.size == 1
                      return @attributes[method] = args.first
                    elsif args.size == 0 && block_given?
        Severity: Minor
        Found in lib/itamae/resource/base.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