app/models/concerns/shared/dual_annotator.rb
Method always_community?
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
Open
def always_community?
case self.class.base_class.name
when 'AlternateValue'
if self.alternate_value_object_type =~ /#{self.class::ALWAYS_COMMUNITY.join('|')}/
- 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
Prefer self[:attr] = val
over write_attribute(:attr, val)
. Open
Open
write_attribute(:project_id, nil) if always_community?
- Read upRead up
- Exclude checks
This cop checks for the use of the read_attribute
or write_attribute
methods and recommends square brackets instead.
If an attribute is missing from the instance (for example, when
initialized by a partial select
) then read_attribute
will return nil, but square brackets will raise
an ActiveModel::MissingAttributeError
.
Explicitly raising an error in this situation is preferable, and that is why rubocop recommends using square brackets.
Example:
# bad
x = read_attribute(:attr)
write_attribute(:attr, val)
# good
x = self[:attr]
self[:attr] = val
TODO found Open
Open
# TODO: change presence of constant, this won't work
- Exclude checks