ryotarai/itamae

Very high overall complexity: 406

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

module Itamae
Found in Itamae::Resource::Base - About 3 days to fix

When classes take on too many responsibilities, they grow. A large number of instance variables or methods can make a class hard to understand. Large classes tend to have lower cohesion and higher churn.

Often large classes have methods that do not operate on all of the class state. Identifying the groups of data that are used together can point to seams to split out additional collaborator classes or value objects.

Another trick is to look for repeated prefixes or suffixes in method and variable names, or repeated parameter names, and use them to guide extractions.

Refactorings

Further Reading

Very complex method in #action_create

      def action_create(options)
        if run_specinfra(:check_user_exists, attributes.username)
          if attributes.uid && attributes.uid != current.uid
            run_specinfra(:update_user_uid, attributes.username, attributes.uid)
            updated!
Found in Itamae::Resource::User - About 2 days to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Very high overall complexity: 254

require 'itamae'

module Itamae
  module Resource
    class File < Base
Found in Itamae::Resource::File - About 1 day to fix

When classes take on too many responsibilities, they grow. A large number of instance variables or methods can make a class hard to understand. Large classes tend to have lower cohesion and higher churn.

Often large classes have methods that do not operate on all of the class state. Identifying the groups of data that are used together can point to seams to split out additional collaborator classes or value objects.

Another trick is to look for repeated prefixes or suffixes in method and variable names, or repeated parameter names, and use them to guide extractions.

Refactorings

Further Reading

High overall complexity: 214

require 'itamae'

module Itamae
  module Resource
    class User < Base
Found in Itamae::Resource::User - About 1 day to fix

When classes take on too many responsibilities, they grow. A large number of instance variables or methods can make a class hard to understand. Large classes tend to have lower cohesion and higher churn.

Often large classes have methods that do not operate on all of the class state. Identifying the groups of data that are used together can point to seams to split out additional collaborator classes or value objects.

Another trick is to look for repeated prefixes or suffixes in method and variable names, or repeated parameter names, and use them to guide extractions.

Refactorings

Further Reading

Very complex method in #run

      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
Found in Itamae::Resource::Base - About 1 day to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Very complex method in #run_action

      def run_action(action)
        runner.handler.event(:action, action: action) do
          original_attributes = @attributes # preserve and restore later
          @current_action = action

Found in Itamae::Resource::Base - About 1 day to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Similar code found in 1 other location

require 'itamae'

module Itamae
  module Resource
    class File < Base
Found in Itamae::Resource::File and 1 other location - About 7 hrs to fix
lib/itamae/resource/remote_directory.rb on lines 26..36

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

Refactorings

Further Reading

Similar code found in 1 other location

require 'itamae'

module Itamae
  module Resource
    class RemoteDirectory < Base
Found in Itamae::Resource::RemoteDirectory and 1 other location - About 7 hrs to fix
lib/itamae/resource/file.rb on lines 33..43

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

Refactorings

Further Reading

Complex method in #set_current_attributes

      def set_current_attributes
        current.exist = exist?

        if current.exist
          current.uid = run_specinfra(:get_user_uid, attributes.username).stdout.strip.to_i
Found in Itamae::Resource::User - About 6 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #action_create

      def action_create(options)
        if !current.exist && !@temppath
          run_command(["touch", attributes.path])
        end

Found in Itamae::Resource::File - About 5 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Similar code found in 1 other location

require 'specinfra/core'
require 'singleton'
require 'io/console'
require 'net/ssh'

Found in Itamae::Backend::Base and 1 other location - About 5 hrs to fix
lib/itamae/backend.rb on lines 101..109

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

Refactorings

Further Reading

Similar code found in 1 other location

require 'specinfra/core'
require 'singleton'
require 'io/console'
require 'net/ssh'

Found in Itamae::Backend::Base and 1 other location - About 5 hrs to fix
lib/itamae/backend.rb on lines 112..120

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

Refactorings

Further Reading

Complex method in #run_command

      def run_command(commands, options = {})
        options = {error: true}.merge(options)

        command = build_command(commands, options)
        Itamae.logger.debug "Executing `#{command}`..."
Found in Itamae::Backend::Base - About 5 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #ssh_options

      def ssh_options
        opts = {}

        opts[:host_name] = @options[:host]

Found in Itamae::Backend::Ssh - About 4 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #create_node

    def create_node
      hash = {}

      if @options[:ohai]
        unless @backend.run_command("which ohai", error: false).exit_status == 0
Found in Itamae::Runner - About 4 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #find_source_file

      def find_source_file
        if attributes.source == :auto
          dirs = attributes.path.split(::File::SEPARATOR)
          dirs.shift if dirs.first == ""

Found in Itamae::Resource::RemoteFile - About 4 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #action_sync

      def action_sync(options)
        ensure_git_available

        new_repository = false

Found in Itamae::Resource::Git - About 4 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #show_differences

      def show_differences
        @current_attributes.each_pair do |key, current_value|
          value = @attributes[key]
          if current_value.nil? && value.nil?
            # ignore
Found in Itamae::Resource::Base - About 4 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #set_current_attributes

      def set_current_attributes
        current.exist = run_specinfra(:check_file_is_file, attributes.path)

        if current.exist
          current.mode = run_specinfra(:get_file_mode, attributes.path).stdout.chomp
Found in Itamae::Resource::File - About 4 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #set_current_attributes

      def set_current_attributes
        current.exist = run_specinfra(:check_file_is_directory, attributes.path)

        if current.exist
          current.mode  = run_specinfra(:get_file_mode, attributes.path).stdout.chomp
Found in Itamae::Resource::RemoteDirectory - About 4 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #set_current_attributes

      def set_current_attributes
        exist = run_specinfra(:check_file_is_directory, attributes.path)
        current.exist = exist

        if exist
Found in Itamae::Resource::Directory - About 4 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #action_create

      def action_create(options)
        if attributes.mode
          run_specinfra(:change_file_mode, @temppath, attributes.mode)
        end
        if attributes.owner || attributes.group
Found in Itamae::Resource::RemoteDirectory - About 3 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #find_recipe_in_gem

      def find_recipe_in_gem(recipe)
        plugin_name, recipe_file = recipe.split('::', 2)
        recipe_file = recipe_file.gsub("::", "/") if recipe_file

        gem_name = "itamae-plugin-recipe-#{plugin_name}"
Found in Itamae::Recipe - About 3 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #action_edit

      def action_edit(options)
        if attributes.mode
          run_specinfra(:change_file_mode, @temppath, attributes.mode)
        else
          run_command(['chmod', '--reference', attributes.path, @temppath])
Found in Itamae::Resource::File - About 3 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #notify

      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?
Found in Itamae::Resource::Base - About 3 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #compare_file

      def compare_file
        compare_to = if current.exist
                       attributes.path
                     else
                       '/dev/null'
Found in Itamae::Resource::File - About 3 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #action_create

      def action_create(options)
        if !run_specinfra(:check_file_is_directory, attributes.path)
          run_specinfra(:create_file_as_directory, attributes.path)
        end
        if attributes.mode
Found in Itamae::Resource::Directory - About 3 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Similar code found in 1 other location

require 'thor'
require 'thor/group'

module Itamae
  module Generators
Found in Itamae::Generators::Cookbook and 1 other location - About 3 hrs to fix
lib/itamae/generators/role.rb on lines 4..18

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

Refactorings

Further Reading

Similar code found in 1 other location

require 'thor'
require 'thor/group'

module Itamae
  module Generators
Found in Itamae::Generators::Role and 1 other location - About 3 hrs to fix
lib/itamae/generators/cookbook.rb on lines 4..18

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

Refactorings

Further Reading

Complex method in #process_attributes

      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)

Found in Itamae::Resource::Base - About 3 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Similar code found in 1 other location

require 'itamae'
require 'thor'

module Itamae
  class CLI < Thor
Found in Itamae::CLI and 1 other location - About 3 hrs to fix
lib/itamae/cli.rb on lines 87..92

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

Refactorings

Further Reading

Similar code found in 1 other location

require 'itamae'
require 'thor'

module Itamae
  class CLI < Thor
Found in Itamae::CLI and 1 other location - About 3 hrs to fix
lib/itamae/cli.rb on lines 97..102

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

Refactorings

Further Reading

Complex method in #action_create

      def action_create(options)
        if run_specinfra(:check_group_exists, attributes.groupname)
          if attributes.gid && attributes.gid != current.gid
            run_specinfra(:update_group_gid, attributes.groupname, attributes.gid)
            updated!
Found in Itamae::Resource::Group - About 3 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #send_tempfile

      def send_tempfile
        if !attributes.content && !content_file
          @temppath = nil
          return
        end
Found in Itamae::Resource::File - About 2 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Similar code found in 1 other location

require 'itamae'

module Itamae
  module Resource
    class Link < Base
Found in Itamae::Resource::Link and 1 other location - About 2 hrs to fix
lib/itamae/resource/package.rb on lines 20..24

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

Refactorings

Further Reading

Similar code found in 1 other location

require 'itamae'

module Itamae
  module Resource
    class Package < Base
Found in Itamae::Resource::Package and 1 other location - About 2 hrs to fix
lib/itamae/resource/link.rb on lines 18..22

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

Refactorings

Further Reading

Complex class definition

require 'itamae'
require 'thor'

module Itamae
  class CLI < Thor
Found in Itamae::CLI - About 2 hrs to fix

    Complex method in #include_recipe

          def include_recipe(target)
            expanded_path = ::File.expand_path(target, File.dirname(@recipe.path))
            expanded_path = ::File.join(expanded_path, 'default.rb') if ::Dir.exists?(expanded_path)
            expanded_path.concat('.rb') unless expanded_path.end_with?('.rb')
            candidate_paths = [expanded_path, Recipe.find_recipe_in_gem(target)].compact
    Found in Itamae::Recipe::EvalContext - About 2 hrs to fix

    Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

    Refactorings

    Read More

    Complex method in #set_current_attributes

          def set_current_attributes
            installed = installed_gems.find {|g| g[:name] == attributes.package_name }
            current.installed = !!installed
    
            if current.installed
    Found in Itamae::Resource::GemPackage - About 2 hrs to fix

    Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

    Refactorings

    Read More

    Complex method in #install!

          def install!
            cmd = [*Array(attributes.gem_binary), 'install']
            if attributes.version
              cmd << '-v' << attributes.version
            end
    Found in Itamae::Resource::GemPackage - About 1 hr to fix

    Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

    Refactorings

    Read More

    Join us for Code Climate
    Summit on July 19 in NYC.

    Tickets on sale now.