app/controllers/configure_controller.rb

Summary

Maintainability
C
7 hrs
Test Coverage

Class has too many lines. [244/100]
Open

class ConfigureController < ApplicationController
  # everything else is handled by application.rb
  before_filter :login_required, only: %i[
    section finish
    done_with_settings zoom_dbs_edit

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

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

  def get_site_linking_progress
    set_kete_net_urls
    begin
      @worker_type = 'site_linking_worker'.to_sym
      @worker_key = worker_key_for(@worker_type)

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 zoom_dbs_update is too high. [41.67/15]
Open

  def zoom_dbs_update
    # TODO: add kill of running zebra instance if possible
    # zebrasrv logs pid in log/zebra.log
    # however zebrasrv spawns processes
    # so killing that pid is usually not enough

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 get_site_linking_progress is too high. [39.94/15]
Open

  def get_site_linking_progress
    set_kete_net_urls
    begin
      @worker_type = 'site_linking_worker'.to_sym
      @worker_key = worker_key_for(@worker_type)

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. [34/10]
Open

  def zoom_dbs_update
    # TODO: add kill of running zebra instance if possible
    # zebrasrv logs pid in log/zebra.log
    # however zebrasrv spawns processes
    # so killing that pid is usually not enough

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. [24/10]
Open

  def send_information
    set_kete_net_urls
    if !request.xhr?
      redirect_to @new_kete_site
    else

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 is too high. [27.82/15]
Open

  def update
    @section = params[:section]

    @settings = SystemSetting.where(section: @section).each { |s| s.value = params[:setting][s.id.to_s][:value] }

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 index is too high. [25.5/15]
Open

  def index
    @advanced = params[:advanced] || false
    @sections = SystemSetting.setup_sections.collect { |s| s }
    if @advanced
      SystemSetting.select(:section).distinct.where('technically_advanced = ? and section not in (?)', true, @sections).each { |advanced_section| @sections << advanced_section.section }

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. [19/10]
Open

  def update
    @section = params[:section]

    @settings = SystemSetting.where(section: @section).each { |s| s.value = params[:setting][s.id.to_s][:value] }

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. [18/10]
Open

  def prime_zebra
    # consolidating the code to do this work by using existing worker
    params[:clear_zebra] = true
    rebuild_zoom_index

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 send_information is too high. [21.31/15]
Open

  def send_information
    set_kete_net_urls
    if !request.xhr?
      redirect_to @new_kete_site
    else

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 prime_zebra is too high. [21.42/15]
Open

  def prime_zebra
    # consolidating the code to do this work by using existing worker
    params[:clear_zebra] = true
    rebuild_zoom_index

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. [14/10]
Open

  def index
    @advanced = params[:advanced] || false
    @sections = SystemSetting.setup_sections.collect { |s| s }
    if @advanced
      SystemSetting.select(:section).distinct.where('technically_advanced = ? and section not in (?)', true, @sections).each { |advanced_section| @sections << advanced_section.section }

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.

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

  def get_site_linking_progress
    set_kete_net_urls
    begin
      @worker_type = 'site_linking_worker'.to_sym
      @worker_key = worker_key_for(@worker_type)

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 zoom_dbs_update is too high. [7/6]
Open

  def zoom_dbs_update
    # TODO: add kill of running zebra instance if possible
    # zebrasrv logs pid in log/zebra.log
    # however zebrasrv spawns processes
    # so killing that pid is usually not enough

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.

Perceived complexity for zoom_dbs_update is too high. [8/7]
Open

  def zoom_dbs_update
    # TODO: add kill of running zebra instance if possible
    # zebrasrv logs pid in log/zebra.log
    # however zebrasrv spawns processes
    # so killing that pid is usually not enough

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

Method get_site_linking_progress has 44 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def get_site_linking_progress
    set_kete_net_urls
    begin
      @worker_type = 'site_linking_worker'.to_sym
      @worker_key = worker_key_for(@worker_type)
Severity: Minor
Found in app/controllers/configure_controller.rb - About 1 hr to fix

    Method zoom_dbs_update has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def zoom_dbs_update
        # TODO: add kill of running zebra instance if possible
        # zebrasrv logs pid in log/zebra.log
        # however zebrasrv spawns processes
        # so killing that pid is usually not enough
    Severity: Minor
    Found in app/controllers/configure_controller.rb - About 1 hr to fix

      Method zoom_dbs_update has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        def zoom_dbs_update
          # TODO: add kill of running zebra instance if possible
          # zebrasrv logs pid in log/zebra.log
          # however zebrasrv spawns processes
          # so killing that pid is usually not enough
      Severity: Minor
      Found in app/controllers/configure_controller.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 get_site_linking_progress has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        def get_site_linking_progress
          set_kete_net_urls
          begin
            @worker_type = 'site_linking_worker'.to_sym
            @worker_key = worker_key_for(@worker_type)
      Severity: Minor
      Found in app/controllers/configure_controller.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 update has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def update
          @section = params[:section]
      
          @settings = SystemSetting.where(section: @section).each { |s| s.value = params[:setting][s.id.to_s][:value] }
      
      
      Severity: Minor
      Found in app/controllers/configure_controller.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 send_information has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def send_information
          set_kete_net_urls
          if !request.xhr?
            redirect_to @new_kete_site
          else
      Severity: Minor
      Found in app/controllers/configure_controller.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

      TODO found
      Open

          # TODO: add kill of running zebra instance if possible

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

        def clear_cache
          ENV['RAILS_ENV'] = Rails.env
          rake_result = Rake::Task['tmp:cache:clear'].execute(ENV)
          if rake_result
            flash[:notice] = t('configure_controller.clear_cache.cache_cleared')
      Severity: Minor
      Found in app/controllers/configure_controller.rb and 1 other location - About 35 mins to fix
      app/controllers/configure_controller.rb on lines 305..314

      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

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

        def restart_server
          ENV['RAILS_ENV'] = Rails.env
          rake_result = Rake::Task['kete:tools:restart'].execute(ENV)
          if rake_result
            flash[:notice] = t('configure_controller.restart_server.server_restarted')
      Severity: Minor
      Found in app/controllers/configure_controller.rb and 1 other location - About 35 mins to fix
      app/controllers/configure_controller.rb on lines 316..325

      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

      Favor unless over if for negative conditions.
      Open

            if !request.xhr?
              redirect_to action: 'index', search_engine_setup: true, search_engine_show: true
            end

      Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:

      - both
      - prefix
      - postfix

      Example: EnforcedStyle: both (default)

      # enforces `unless` for `prefix` and `postfix` conditionals
      
      # bad
      
      if !foo
        bar
      end
      
      # good
      
      unless foo
        bar
      end
      
      # bad
      
      bar if !foo
      
      # good
      
      bar unless foo

      Example: EnforcedStyle: prefix

      # enforces `unless` for just `prefix` conditionals
      
      # bad
      
      if !foo
        bar
      end
      
      # good
      
      unless foo
        bar
      end
      
      # good
      
      bar if !foo

      Example: EnforcedStyle: postfix

      # enforces `unless` for just `postfix` conditionals
      
      # bad
      
      bar if !foo
      
      # good
      
      bar unless foo
      
      # good
      
      if !foo
        bar
      end

      Pass &:add_error_if_required as an argument to each instead of a block.
      Open

          @settings.each { |s| s.add_error_if_required }

      Use symbols as procs when possible.

      Example:

      # bad
      something.map { |s| s.upcase }
      
      # good
      something.map(&:upcase)

      Do not use unless with else. Rewrite these with the positive case first.
      Open

              unless backgroundrb_is_running?(@worker_type)
                MiddleMan.new_worker(worker: @worker_type, worker_key: @worker_key)
                MiddleMan.worker(@worker_type, @worker_key).async_do_work(arg: { params: params })
                render :update do |page|
                  page.replace_html('updater', periodically_call_remote(url: { action: 'get_site_linking_progress' }, frequency: 10))

      This cop looks for unless expressions with else clauses.

      Example:

      # bad
      unless foo_bar.nil?
        # do something...
      else
        # do a different thing...
      end
      
      # good
      if foo_bar.present?
        # do something...
      else
        # do a different thing...
      end

      Favor unless over if for negative conditions.
      Open

            if !request.xhr?
              redirect_to action: 'index'
            end

      Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:

      - both
      - prefix
      - postfix

      Example: EnforcedStyle: both (default)

      # enforces `unless` for `prefix` and `postfix` conditionals
      
      # bad
      
      if !foo
        bar
      end
      
      # good
      
      unless foo
        bar
      end
      
      # bad
      
      bar if !foo
      
      # good
      
      bar unless foo

      Example: EnforcedStyle: prefix

      # enforces `unless` for just `prefix` conditionals
      
      # bad
      
      if !foo
        bar
      end
      
      # good
      
      unless foo
        bar
      end
      
      # good
      
      bar if !foo

      Example: EnforcedStyle: postfix

      # enforces `unless` for just `postfix` conditionals
      
      # bad
      
      bar if !foo
      
      # good
      
      bar unless foo
      
      # good
      
      if !foo
        bar
      end

      Closing array brace must be on the line after the last array element when opening brace is on a separate line from the first array element.
      Open

          index]

      This cop checks that the closing brace in an array literal is either on the same line as the last array element, or a new line.

      When using the symmetrical (default) style:

      If an array's opening brace is on the same line as the first element of the array, then the closing brace should be on the same line as the last element of the array.

      If an array's opening brace is on the line above the first element of the array, then the closing brace should be on the line below the last element of the array.

      When using the new_line style:

      The closing brace of a multi-line array literal must be on the line after the last element of the array.

      When using the same_line style:

      The closing brace of a multi-line array literal must be on the same line as the last element of the array.

      Example: EnforcedStyle: symmetrical (default)

      # bad
        [ :a,
          :b
        ]
      
        # bad
        [
          :a,
          :b ]
      
        # good
        [ :a,
          :b ]
      
        # good
        [
          :a,
          :b
        ]

      Example: EnforcedStyle: new_line

      # bad
        [
          :a,
          :b ]
      
        # bad
        [ :a,
          :b ]
      
        # good
        [ :a,
          :b
        ]
      
        # good
        [
          :a,
          :b
        ]

      Example: EnforcedStyle: same_line

      # bad
        [ :a,
          :b
        ]
      
        # bad
        [
          :a,
          :b
        ]
      
        # good
        [
          :a,
          :b ]
      
        # good
        [ :a,
          :b ]

      Do not prefix reader method names with get_.
      Open

        def get_site_linking_progress

      This cop makes sure that accessor methods are named properly.

      Example:

      # bad
      def set_attribute(value)
      end
      
      # good
      def attribute=(value)
      end
      
      # bad
      def get_attribute
      end
      
      # good
      def attribute
      end

      Avoid rescuing without specifying an error class.
      Open

          rescue

      This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

      Example: EnforcedStyle: implicit

      # `implicit` will enforce using `rescue` instead of
      # `rescue StandardError`.
      
      # bad
      begin
        foo
      rescue StandardError
        bar
      end
      
      # good
      begin
        foo
      rescue
        bar
      end
      
      # good
      begin
        foo
      rescue OtherError
        bar
      end
      
      # good
      begin
        foo
      rescue StandardError, SecurityError
        bar
      end

      Example: EnforcedStyle: explicit (default)

      # `explicit` will enforce using `rescue StandardError`
      # instead of `rescue`.
      
      # bad
      begin
        foo
      rescue
        bar
      end
      
      # good
      begin
        foo
      rescue StandardError
        bar
      end
      
      # good
      begin
        foo
      rescue OtherError
        bar
      end
      
      # good
      begin
        foo
      rescue StandardError, SecurityError
        bar
      end

      Symbol with a boolean name - you probably meant to use true.
      Open

            redirect_to action: 'index', ready_to_restart: :true

      This cop checks for :true and :false symbols. In most cases it would be a typo.

      Example:

      # bad
      :true
      
      # good
      true

      Example:

      # bad
      :false
      
      # good
      false

      Useless private access modifier.
      Open

        private

      This cop checks for redundant access modifiers, including those with no code, those which are repeated, and leading public modifiers in a class or module body. Conditionally-defined methods are considered as always being defined, and thus access modifiers guarding such methods are not redundant.

      Example:

      class Foo
        public # this is redundant (default access is public)
      
        def method
        end
      
        private # this is not redundant (a method is defined)
        def method2
        end
      
        private # this is redundant (no following methods are defined)
      end

      Example:

      class Foo
        # The following is not redundant (conditionally defined methods are
        # considered as always defining a method)
        private
      
        if condition?
          def method
          end
        end
      
        protected # this is not redundant (method is defined)
      
        define_method(:method2) do
        end
      
        protected # this is redundant (repeated from previous modifier)
      
        [1,2,3].each do |i|
          define_method("foo#{i}") do
          end
        end
      
        # The following is redundant (methods defined on the class'
        # singleton class are not affected by the public modifier)
        public
      
        def self.method3
        end
      end

      Example:

      # Lint/UselessAccessModifier:
      #   ContextCreatingMethods:
      #     - concerning
      require 'active_support/concern'
      class Foo
        concerning :Bar do
          def some_public_method
          end
      
          private
      
          def some_private_method
          end
        end
      
        # this is not redundant because `concerning` created its own context
        private
      
        def some_other_private_method
        end
      end

      Example:

      # Lint/UselessAccessModifier:
      #   MethodCreatingMethods:
      #     - delegate
      require 'active_support/core_ext/module/delegation'
      class Foo
        # this is not redundant because `delegate` creates methods
        private
      
        delegate :method_a, to: :method_b
      end

      Avoid rescuing without specifying an error class.
      Open

            rescue

      This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

      Example: EnforcedStyle: implicit

      # `implicit` will enforce using `rescue` instead of
      # `rescue StandardError`.
      
      # bad
      begin
        foo
      rescue StandardError
        bar
      end
      
      # good
      begin
        foo
      rescue
        bar
      end
      
      # good
      begin
        foo
      rescue OtherError
        bar
      end
      
      # good
      begin
        foo
      rescue StandardError, SecurityError
        bar
      end

      Example: EnforcedStyle: explicit (default)

      # `explicit` will enforce using `rescue StandardError`
      # instead of `rescue`.
      
      # bad
      begin
        foo
      rescue
        bar
      end
      
      # good
      begin
        foo
      rescue StandardError
        bar
      end
      
      # good
      begin
        foo
      rescue OtherError
        bar
      end
      
      # good
      begin
        foo
      rescue StandardError, SecurityError
        bar
      end

      Use a guard clause instead of wrapping the code inside a conditional expression.
      Open

          if @success && !request.xhr?

      Use a guard clause instead of wrapping the code inside a conditional expression

      Example:

      # bad
      def test
        if something
          work
        end
      end
      
      # good
      def test
        return unless something
        work
      end
      
      # also good
      def test
        work if something
      end
      
      # bad
      if something
        raise 'exception'
      else
        ok
      end
      
      # good
      raise 'exception' if something
      ok

      Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
      Open

            if !request.xhr?

      Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

      Example:

      # bad
      if condition
        do_stuff(bar)
      end
      
      unless qux.empty?
        Foo.do_something
      end
      
      # good
      do_stuff(bar) if condition
      Foo.do_something unless qux.empty?

      There are no issues that match your filters.

      Category
      Status