Mass assignment is not restricted using attr_accessible Open
class Document < ActiveRecord::Base
- Read upRead up
- Exclude checks
This warning comes up if a model does not limit what attributes can be set through mass assignment.
In particular, this check looks for attr_accessible
inside model definitions. If it is not found, this warning will be issued.
Brakeman also warns on use of attr_protected
- especially since it was found to be vulnerable to bypass. Warnings for mass assignment on models using attr_protected
will be reported, but at a lower confidence level.
Note that disabling mass assignment globally will suppress these warnings.
Assignment Branch Condition size for updated_since is too high. [27.89/15] Open
def self.updated_since(date)
# Document.where( <Document or its join tables is newer than date> )
documents = ::Document.arel_table
taggings = Tagging.arel_table
- 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. [19/10] Open
def self.updated_since(date)
# Document.where( <Document or its join tables is newer than date> )
documents = ::Document.arel_table
taggings = Tagging.arel_table
- 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.
Assignment Branch Condition size for attachment_attributes_valid? is too high. [21.4/15] Open
def attachment_attributes_valid?
%i[size content_type].each do |attr_name|
enum = attachment_options[attr_name]
if attr_name.to_s == 'content_type' && !enum.blank?
logger.debug("what is received #{attr_name}: " + send(attr_name).inspect)
- 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. [12/10] Open
def attachment_attributes_valid?
%i[size content_type].each do |attr_name|
enum = attachment_options[attr_name]
if attr_name.to_s == 'content_type' && !enum.blank?
logger.debug("what is received #{attr_name}: " + send(attr_name).inspect)
- 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.
Method attachment_attributes_valid?
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def attachment_attributes_valid?
%i[size content_type].each do |attr_name|
enum = attachment_options[attr_name]
if attr_name.to_s == 'content_type' && !enum.blank?
logger.debug("what is received #{attr_name}: " + send(attr_name).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
TODO found Open
# TODO: needs some of the new filetypes like openoffice, pages, plenty of old ones, too
- Exclude checks
TODO found Open
# TODO: add more content_types
- Exclude checks
Use \
instead of +
or <<
to concatenate those strings. Open
.joins('LEFT OUTER JOIN deleted_content_item_relations ' +
- Read upRead up
- Exclude checks
This cop checks for string literal concatenation at the end of a line.
Example:
# bad
some_str = 'ala' +
'bala'
some_str = 'ala' <<
'bala'
# good
some_str = 'ala' \
'bala'
Use next
to skip iteration. Open
unless enum.nil? || enum.include?(send(attr_name))
- Read upRead up
- Exclude checks
Use next
to skip iteration instead of a condition at the end.
Example: EnforcedStyle: skipmodifierifs (default)
# bad
[1, 2].each do |a|
if a == 1
puts a
end
end
# good
[1, 2].each do |a|
next unless a == 1
puts a
end
# good
[1, 2].each do |o|
puts o unless o == 1
end
Example: EnforcedStyle: always
# With `always` all conditions at the end of an iteration needs to be
# replaced by next - with `skip_modifier_ifs` the modifier if like
# this one are ignored: `[1, 2].each { |a| return 'yes' if a == 1 }`
# bad
[1, 2].each do |o|
puts o unless o == 1
end
# bad
[1, 2].each do |a|
if a == 1
puts a
end
end
# good
[1, 2].each do |a|
next unless a == 1
puts a
end
Use \
instead of +
or <<
to concatenate those strings. Open
'ON deleted_content_item_relations.related_item_id = documents.id ' +
- Read upRead up
- Exclude checks
This cop checks for string literal concatenation at the end of a line.
Example:
# bad
some_str = 'ala' +
'bala'
some_str = 'ala' <<
'bala'
# good
some_str = 'ala' \
'bala'