ekylibre/active_list

View on GitHub
lib/active_list/renderers/simple_renderer.rb

Summary

Maintainability
F
6 days
Test Coverage

Method columns_to_cells has a Cognitive Complexity of 101 (exceeds 5 allowed). Consider refactoring.
Open

      def columns_to_cells(nature, options = {})
        code = ''
        unless %i[body children].include?(nature)
          raise ArgumentError, 'Nature is invalid'
        end
Severity: Minor
Found in lib/active_list/renderers/simple_renderer.rb - About 2 days 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

File simple_renderer.rb has 387 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module ActiveList
  module Renderers
    class SimpleRenderer < AbstractRenderer
      include ActiveList::Helpers

Severity: Minor
Found in lib/active_list/renderers/simple_renderer.rb - About 5 hrs to fix

    Method columns_to_cells has 100 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def columns_to_cells(nature, options = {})
            code = ''
            unless %i[body children].include?(nature)
              raise ArgumentError, 'Nature is invalid'
            end
    Severity: Major
    Found in lib/active_list/renderers/simple_renderer.rb - About 4 hrs to fix

      Method column_classes has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

            def column_classes(column, without_id = false, without_interpolation = false)
              classes = []
              conds = []
              conds << [:sor, "#{var_name(:params)}[:sort] == '#{column.sort_id}'".c] if column.sortable?
              conds << [:hidden, "#{var_name(:params)}[:hidden_columns].include?(:#{column.name})".c] if column.is_a? ActiveList::Definition::DataColumn
      Severity: Minor
      Found in lib/active_list/renderers/simple_renderer.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

      Method build_table_code has 89 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def build_table_code(options = {})
              record = 'r'
      
              # colgroup = columns_definition_code
              header = header_code
      Severity: Major
      Found in lib/active_list/renderers/simple_renderer.rb - About 3 hrs to fix

        Method extras_codes has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

              def extras_codes
                code = []
        
                codes = {}
                if table.global_action_columns.any?
        Severity: Minor
        Found in lib/active_list/renderers/simple_renderer.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 build_table_code has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

              def build_table_code(options = {})
                record = 'r'
        
                # colgroup = columns_definition_code
                header = header_code
        Severity: Minor
        Found in lib/active_list/renderers/simple_renderer.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 header_code has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

              def header_code
                code = ''
                code << "'<thead><tr>"
                if table.selectable?
                  code << '<th class="list-selector"><input type="checkbox" data-list-selector="all" /></th>'
        Severity: Minor
        Found in lib/active_list/renderers/simple_renderer.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 column_classes has 44 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def column_classes(column, without_id = false, without_interpolation = false)
                classes = []
                conds = []
                conds << [:sor, "#{var_name(:params)}[:sort] == '#{column.sort_id}'".c] if column.sortable?
                conds << [:hidden, "#{var_name(:params)}[:hidden_columns].include?(:#{column.name})".c] if column.is_a? ActiveList::Definition::DataColumn
        Severity: Minor
        Found in lib/active_list/renderers/simple_renderer.rb - About 1 hr to fix

          Method extras_codes has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def extras_codes
                  code = []
          
                  codes = {}
                  if table.global_action_columns.any?
          Severity: Minor
          Found in lib/active_list/renderers/simple_renderer.rb - About 1 hr to fix

            Method header_code has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def header_code
                    code = ''
                    code << "'<thead><tr>"
                    if table.selectable?
                      code << '<th class="list-selector"><input type="checkbox" data-list-selector="all" /></th>'
            Severity: Minor
            Found in lib/active_list/renderers/simple_renderer.rb - About 1 hr to fix

              Method menu_code has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def menu_code
                      menu = "<span class=\"list-settings\" data-list-ref=\"#{uid}\">"
                      menu << "<a class=\"settings-start\"><i></i>' + h('list.menu'.t) + '</a>"
                      menu << '<ul>'
                      if table.paginate?
              Severity: Minor
              Found in lib/active_list/renderers/simple_renderer.rb - About 1 hr to fix

                Avoid deeply nested control flow statements.
                Open

                                currency = :currency if currency.is_a?(TrueClass)
                Severity: Major
                Found in lib/active_list/renderers/simple_renderer.rb - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                  currency = currency[nature] if currency.is_a?(Hash)
                  Severity: Major
                  Found in lib/active_list/renderers/simple_renderer.rb - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                    column.options[:url] = {} unless column.options[:url].is_a?(Hash)
                    Severity: Major
                    Found in lib/active_list/renderers/simple_renderer.rb - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                  value_code = (nature == :body ? "text_field_tag(#{form_name.inspect}, #{recordify!(column.options[:value] || column.name, record)}#{column.options[:size] ? ', size: ' + column.options[:size].to_s : ''})" : 'nil') # , id: '#{table.name}_'+#{record}.id.to_s + '_#{column.name}'
                      Severity: Major
                      Found in lib/active_list/renderers/simple_renderer.rb - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                      elsif column.options[:mode] || column.label_method == :email
                                        value_code = "(#{value_code}.blank? ? '' : mail_to(#{value_code}))"
                                      elsif column.options[:mode] || column.label_method == :website
                                        value_code = "(#{value_code}.blank? ? '' : link_to(" + value_code + ', ' + value_code + '))'
                                      elsif column.label_method == :color
                        Severity: Major
                        Found in lib/active_list/renderers/simple_renderer.rb - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                          currency = "#{column.record_expr(record)}.#{currency}".c if currency.is_a?(Symbol)
                          Severity: Major
                          Found in lib/active_list/renderers/simple_renderer.rb - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                          if column.form_value
                                            value = recordify(column.form_value, record)
                                          else
                                            value = 1
                                            value_code << "hidden_field_tag(#{form_name.inspect}, 0, id: nil) + \n"
                            Severity: Major
                            Found in lib/active_list/renderers/simple_renderer.rb - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                            elsif column.datatype == :decimal
                                              value_code = "(#{value_code}.nil? ? '' : #{value_code}.l)"
                                            elsif column.enumerize?
                                              value_code = "(#{value_code}.nil? ? '' : #{value_code}.text)"
                              Severity: Major
                              Found in lib/active_list/renderers/simple_renderer.rb - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                          elsif column.is_a?(ActiveList::Definition::ActionColumn)
                                            next unless column.use_single?
                                            value_code = (nature == :body ? column.operation(record) : 'nil')
                                          else
                                            value_code = "'&#160;&#8709;&#160;'.html_safe"
                                Severity: Major
                                Found in lib/active_list/renderers/simple_renderer.rb - About 45 mins to fix

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

                                            pagination << "<span class=\"status\">' + 'list.pagination.x_to_y_of_total'.t(x: (#{var_name(:offset)} + (#{var_name(:count)} > 0 ? 1 : 0)), y: ((#{var_name(:last)} == #{var_name(:page)}) ? #{var_name(:count)} : #{var_name(:offset)} + #{var_name(:limit)}), total: #{var_name(:count)}) + '</span>"
                                  Severity: Minor
                                  Found in lib/active_list/renderers/simple_renderer.rb and 1 other location - About 35 mins to fix
                                  lib/active_list/renderers/simple_renderer.rb on lines 393..393

                                  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

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

                                              pagination << "<span class=\"status\">' + 'list.pagination.x_to_y_of_total'.t(x: (#{var_name(:offset)} + (#{var_name(:count)} > 0 ? 1 : 0)), y: ((#{var_name(:last)} == #{var_name(:page)}) ? #{var_name(:count)} : #{var_name(:offset)} + #{var_name(:limit)}), total: #{var_name(:count)}) + '</span>"
                                  Severity: Minor
                                  Found in lib/active_list/renderers/simple_renderer.rb and 1 other location - About 35 mins to fix
                                  lib/active_list/renderers/simple_renderer.rb on lines 374..374

                                  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

                                  There are no issues that match your filters.

                                  Category
                                  Status