Showing 235 of 235 total issues
Cyclomatic complexity for build_from is too high. [8/6] Open
def self.build_from(object: nil, exception: nil, class_name: nil, type: nil)
if object
args = [:message, :original_error, :level, :type, :class_name].each_with_object({}) do |meth, hash|
hash[meth] = object.public_send(meth) if object.respond_to? meth
end
- Read upRead up
- Exclude checks
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 build_from is too high. [9/7] Open
def self.build_from(object: nil, exception: nil, class_name: nil, type: nil)
if object
args = [:message, :original_error, :level, :type, :class_name].each_with_object({}) do |meth, hash|
hash[meth] = object.public_send(meth) if object.respond_to? meth
end
- Read upRead up
- Exclude checks
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
Assignment Branch Condition size for safe_methods is too high. [16.4/15] (http://c2.com/cgi/wiki?AbcMetric) Open
def safe_methods
@safe_methods ||= class_introspector.parsed_source.comments.each_with_object(BASE.dup) do |comment, hash|
if comment.text.include?("ActiveMocker.all_methods_safe")
hash[:all_methods_safe] = ActiveMocker.module_eval(comment.text.delete("#"))
elsif comment.text.include?("ActiveMocker.safe_methods")
- Read upRead up
- Exclude checks
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 collect_errors is too high. [16.28/15] (http://c2.com/cgi/wiki?AbcMetric) Open
def collect_errors(create_mock_errors)
add_errors!
if create_mock_errors.present? || schema.attribute_errors?
display_errors.failed_models << model_name
- Read upRead up
- Exclude checks
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. [11/10] (https://github.com/bbatsov/ruby-style-guide#short-methods) Open
def scope_body(_arguments, name)
if safe_method?(:scope, name)
find_scope_body_from_ast(name)
else
<<-METHOD
- Read upRead up
- Exclude checks
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 object_for_inspect is too high. [8/7] Open
def object_for_inspect(value)
if value.is_a?(String) && value.length > 50
"#{value[0, 50]}...".inspect
elsif value.is_a?(Date) || value.is_a?(Time)
%("#{value.to_s(:db)}")
- Read upRead up
- Exclude checks
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
Assignment Branch Condition size for build is too high. [16.67/15] (http://c2.com/cgi/wiki?AbcMetric) Open
def build(db_value_type:, table_name:, attribute:, enums:, ignore_value: false)
klass = Class.new(ActiveMocker::AttributeTypes::Enum)
klass.table_name = table_name.to_sym
klass.attribute = attribute.to_sym
klass.ignore_value = ignore_value
- Read upRead up
- Exclude checks
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 object_for_inspect is too high. [16.19/15] (http://c2.com/cgi/wiki?AbcMetric) Open
def object_for_inspect(value)
if value.is_a?(String) && value.length > 50
"#{value[0, 50]}...".inspect
elsif value.is_a?(Date) || value.is_a?(Time)
%("#{value.to_s(:db)}")
- Read upRead up
- Exclude checks
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. [11/10] (https://github.com/bbatsov/ruby-style-guide#short-methods) Open
def coerce(key)
return if key.nil?
coerced_key = key_type.coerce(key)
if key && self.class.enums.key?(coerced_key)
if self.class.ignore_value
- Read upRead up
- Exclude checks
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 object_for_inspect is too high. [7/6] Open
def object_for_inspect(value)
if value.is_a?(String) && value.length > 50
"#{value[0, 50]}...".inspect
elsif value.is_a?(Date) || value.is_a?(Time)
%("#{value.to_s(:db)}")
- Read upRead up
- Exclude checks
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 class_method_calls is too high. [15.3/15] (http://c2.com/cgi/wiki?AbcMetric) Open
def class_method_calls
@class_method_calls ||= class_introspector
.class_macros
.select { |h| h.keys.first == :alias_attribute }
.map do |h|
- Read upRead up
- Exclude checks
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 mock_build_version is too high. [15.33/15] (http://c2.com/cgi/wiki?AbcMetric) Open
def mock_build_version(version, active_record: nil)
@active_record_build_version = Gem::Version.create(active_record)
if __active_record_build_version__ >= Gem::Version.create("5.1")
require "active_mocker/mock/compatibility/base/ar51"
extend AR51
- Read upRead up
- Exclude checks
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 create_method
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def create_method(m, type)
plural_type = (type.to_s + "s").to_sym
if safe_method?(type, m)
def_type = type == :method ? :class_defs : :defs
def_method = class_introspector.parsed_source.public_send(def_type).detect { |meth| meth.name == m }
- Read upRead up
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 process_attr
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def process_attr(attr)
enums = enums(attr.name)
attr.default = Virtus::Attribute.build(attr.type).coerce(attr.default)
attr.attribute_writer = "write_attribute(:#{attr.name}, val)"
attr.attribute_reader = "read_attribute(:#{attr.name})"
- Read upRead up
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 process_attr
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def process_attr(attr)
enums = enums(attr.name)
attr.default = Virtus::Attribute.build(attr.type).coerce(attr.default)
attr.attribute_writer = "write_attribute(:#{attr.name}, val)"
attr.attribute_reader = "read_attribute(:#{attr.name})"
Avoid parameter lists longer than 5 parameters. [10/5] (https://github.com/bbatsov/ruby-style-guide#too-many-params) Open
def initialize(file:,
file_out:,
schema_scrapper:,
template_creator: nil,
class_introspector: nil,
- Read upRead up
- Exclude checks
This cop checks for methods with too many parameters. The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count.
Method coerce
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def coerce(key)
return if key.nil?
coerced_key = key_type.coerce(key)
if key && self.class.enums.key?(coerced_key)
if self.class.ignore_value
- Read upRead up
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 object_for_inspect
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def object_for_inspect(value)
if value.is_a?(String) && value.length > 50
"#{value[0, 50]}...".inspect
elsif value.is_a?(Date) || value.is_a?(Time)
%("#{value.to_s(:db)}")
- Read upRead up
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 constants
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def constants
class_introspector.get_class.constants.map do |v|
c = class_introspector.get_class.const_get(v)
next if [Module, Class].include?(c.class)
const = if /\A#</ =~ c.inspect
- Read upRead up
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 display_errors
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def display_errors
uniq_errors.each do |e|
next unless ENV["DEBUG"] || !(e.level == :debug)
display_verbosity_three(e) || display_verbosity_two(e)
- Read upRead up
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"