rambler-digital-solutions/Generamba

View on GitHub

Showing 840 of 840 total issues

Method initialize has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    def initialize(name, rambafile, options)
      # Base initialization
      @name = name
      @description = options[:description] ? options[:description] : "#{name} module"
      @author = rambafile[AUTHOR_NAME_KEY] ? rambafile[AUTHOR_NAME_KEY] : UserPreferences.obtain_username
Severity: Minor
Found in lib/generamba/code_generation/code_module.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 has too many lines. [15/10]
Open

    def create_template(properties)
      template_dir_path = Pathname.new(File.dirname(__FILE__)).join(NEW_TEMPLATE_FOLDER)
      rambaspec_template_file_path = template_dir_path.join(RAMBASPEC_TEMPLATE_NAME)
      code_file_path = template_dir_path.join(CODE_FOLDER)
      tests_file_path = template_dir_path.join(TESTS_FOLDER)

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [15/10]
Open

    def install_templates(rambafile)
      # We always clear previously installed templates to avoid conflicts in different versions
      clear_installed_templates

      templates = rambafile[TEMPLATES_KEY]

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for all_nil_mandatory_fields_for_target_type is too high. [20.83/15]
Open

    def all_nil_mandatory_fields_for_target_type(target_type, code_module)
      fields = []

      variable_name = "#{target_type}_targets"

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [15/10]
Open

    def all_nil_mandatory_fields_for_target_type(target_type, code_module)
      fields = []

      variable_name = "#{target_type}_targets"

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [15/10]
Open

    def search(term)
      downloader = CatalogDownloader.new
      catalog_template_search_helper = CatalogTemplateSearchHelper.new

      catalog_paths = downloader.update_all_catalogs_and_return_filepaths

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [14/10]
Open

    def self.check_all_required_dependencies_has_in_podfile(dependencies, podfile_path)
      return if !dependencies || dependencies.count == 0 || !podfile_path

      dependencies_names = []
      Pod::Podfile.from_file(Pathname.new(podfile_path)).dependencies.each do |dependency|

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [14/10]
Open

    def initialize(name, options = nil)
      spec_path = TemplateHelper.obtain_spec(name)

      unless options
        spec = YAML.load_file(spec_path)

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [13/10]
Open

    def update_catalogs_if_needed(catalogs, templates)
      needs_update = templates.any? {|template| template.type == TemplateDeclarationType::CATALOG_TEMPLATE}

      return unless needs_update

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for update_all_catalogs_and_return_filepaths is too high. [18.63/15]
Open

    def update_all_catalogs_and_return_filepaths
      does_rambafile_exist = Dir[RAMBAFILE_NAME].count > 0

      if does_rambafile_exist
        rambafile = YAML.load_file(RAMBAFILE_NAME)

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for install_template is too high. [18.49/15]
Open

    def install_template(template_declaration)
      template_name = template_declaration.name
      puts("Installing #{template_name}...")

      local_path = template_declaration.local

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for check_all_required_dependencies_has_in_podfile is too high. [18.79/15]
Open

    def self.check_all_required_dependencies_has_in_podfile(dependencies, podfile_path)
      return if !dependencies || dependencies.count == 0 || !podfile_path

      dependencies_names = []
      Pod::Podfile.from_file(Pathname.new(podfile_path)).dependencies.each do |dependency|

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for create_file is too high. [18.03/15]
Open

        def self.create_file(file, scope, template)
            file_source = IO.read(template.template_path.join(file[TEMPLATE_FILE_PATH_KEY]))
            Liquid::Template.file_system = Liquid::LocalFileSystem.new(template.template_path.join('snippets'), '%s.liquid')

            template = Liquid::Template.parse(file_source)

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Cyclomatic complexity for setup_file_and_group_paths is too high. [9/6]
Open

    def setup_file_and_group_paths(file_path, group_path, path_type)
      if file_path || group_path
        variable_name = "#{path_type}_file_path"

        if file_path || !instance_variable_get("@#{variable_name}")

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Method has too many lines. [12/10]
Open

    def download_catalog(name, url)
      catalogs_local_path = Pathname.new(ENV['HOME'])
                               .join(GENERAMBA_HOME_DIR)
                               .join(CATALOGS_DIR)
      current_catalog_path = catalogs_local_path

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for remove_all_catalogs is too high. [17.15/15]
Open

    def remove_all_catalogs
      catalogs_path = Pathname.new(ENV['HOME'])
                          .join(GENERAMBA_HOME_DIR)
                          .join(CATALOGS_DIR)
      if Dir.exist?(catalogs_path) == false

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Perceived complexity for retrieve_group_or_create_if_needed is too high. [9/7]
Open

    def self.retrieve_group_or_create_if_needed(group_path, dir_path, file_group_path, project, create_group_if_not_exists, group_is_logical = false)
      group_names = path_names_from_path(group_path)
      group_components_count = group_names.count
      group_names += path_names_from_path(file_group_path) if file_group_path

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Perceived complexity for setup_file_and_group_paths is too high. [9/7]
Open

    def setup_file_and_group_paths(file_path, group_path, path_type)
      if file_path || group_path
        variable_name = "#{path_type}_file_path"

        if file_path || !instance_variable_get("@#{variable_name}")

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Cyclomatic complexity for retrieve_group_or_create_if_needed is too high. [8/6]
Open

    def self.retrieve_group_or_create_if_needed(group_path, dir_path, file_group_path, project, create_group_if_not_exists, group_is_logical = false)
      group_names = path_names_from_path(group_path)
      group_components_count = group_names.count
      group_names += path_names_from_path(file_group_path) if file_group_path

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Method has too many lines. [12/10]
Open

        def self.create_file(file, scope, template)
            file_source = IO.read(template.template_path.join(file[TEMPLATE_FILE_PATH_KEY]))
            Liquid::Template.file_system = Liquid::LocalFileSystem.new(template.template_path.join('snippets'), '%s.liquid')

            template = Liquid::Template.parse(file_source)

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Severity
Category
Status
Source
Language