# kaminari/kaminari

### Showing 279 of 279 total issues

#### Assignment Branch Condition size for total_count is too high. [33.44/15] Open

``````    def total_count(column_name = :all, _options = nil) #:nodoc:
return @total_count if defined?(@total_count) && @total_count

# There are some cases that total count can be deduced from loaded records

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

``````    def total_count(column_name = :all, _options = nil) #:nodoc:
return @total_count if defined?(@total_count) && @total_count

# There are some cases that total count can be deduced from loaded records

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

``````    def total_count(column_name = :all, _options = nil) #:nodoc:
return @total_count if defined?(@total_count) && @total_count

# There are some cases that total count can be deduced from loaded records

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.

#### Assignment Branch Condition size for per is too high. [23.75/15] Open

``````    def per(num, max_per_page: nil)
max_per_page ||= ((defined?(@_max_per_page) && @_max_per_page) || self.max_per_page)
@_per = (num || default_per_page).to_i
if (n = num.to_i) < 0 || !(/^\d/ =~ num.to_s)
self``````

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

``````    def total_count(column_name = :all, _options = nil) #:nodoc:
return @total_count if defined?(@total_count) && @total_count

# There are some cases that total count can be deduced from loaded records

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

``````      def relevant_pages(options)
left_window_plus_one = [*1..options[:left] + 1]
right_window_plus_one = [*options[:total_pages] - options[:right]..options[:total_pages]]
inside_window_plus_each_sides = [*options[:current_page] - options[:window] - 1..options[:current_page] + options[:window] + 1]

``````

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

``````      def page_entries_info(collection, entry_name: nil)
entry_name = if entry_name
entry_name.pluralize(collection.size, I18n.locale)
else
collection.entry_name(count: collection.size).downcase``````

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

``````      def copy_or_fetch #:nodoc:
return copy_default_views if file_name == 'default'

if (theme = self.class.themes.detect {|t| t.name == file_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

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

``````      def initialize(template, params: nil, param_name: nil, theme: nil, views_prefix: nil, internal_params: nil, **options) #:nodoc:
@template, @theme, @views_prefix, @options = template, theme, views_prefix, options
@param_name = param_name || Kaminari.config.param_name

if internal_params``````

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

``````      def params_for(page)
if (@param_name == :page) || !@param_name.include?('[')
page_val = !Kaminari.config.params_on_first_page && (page <= 1) ? nil : page
@params[@param_name] = page_val
@params``````

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

``````        def set_limit_value(new_limit)
@values[:limit] = new_limit

if @arel
case @arel.limit.class.name``````

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.

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

``````    def per(num, max_per_page: nil)
max_per_page ||= ((defined?(@_max_per_page) && @_max_per_page) || self.max_per_page)
@_per = (num || default_per_page).to_i
if (n = num.to_i) < 0 || !(/^\d/ =~ num.to_s)
self``````

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

``````    def load
if loaded? || limit_value.nil?
super
else
set_limit_value limit_value + 1``````

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

``````    def per(num, max_per_page: nil)
max_per_page ||= ((defined?(@_max_per_page) && @_max_per_page) || self.max_per_page)
@_per = (num || default_per_page).to_i
if (n = num.to_i) < 0 || !(/^\d/ =~ num.to_s)
self``````

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 `total_count` has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open

``````    def total_count(column_name = :all, _options = nil) #:nodoc:
return @total_count if defined?(@total_count) && @total_count

# There are some cases that total count can be deduced from loaded records

# 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"

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

``````    def initialize(original_array = [], limit: nil, offset: nil, total_count: nil, padding: nil)
@_original_array, @_limit_value, @_offset_value, @_total_count, @_padding = original_array, (limit || default_per_page).to_i, offset.to_i, total_count, padding.to_i

if limit && offset
extend Kaminari::PageScopeMethods``````

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.

#### Assignment Branch Condition size for load is too high. [17.97/15] Open

``````    def load
if loaded? || limit_value.nil?
super
else
set_limit_value limit_value + 1``````

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

``````      def params_for(page)
if (@param_name == :page) || !@param_name.include?('[')
page_val = !Kaminari.config.params_on_first_page && (page <= 1) ? nil : page
@params[@param_name] = page_val
@params``````

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

``````      def initialize(template, window: nil, outer_window: Kaminari.config.outer_window, left: Kaminari.config.left, right: Kaminari.config.right, inner_window: Kaminari.config.window, **options) #:nodoc:
super template, **options

@window_options = {window: window || inner_window, left: left.zero? ? outer_window : left, right: right.zero? ? outer_window : right}

``````

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

``````      def page_entries_info(collection, entry_name: nil)
entry_name = if entry_name
entry_name.pluralize(collection.size, I18n.locale)
else
collection.entry_name(count: collection.size).downcase``````

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.