lib/course_meetings_manager.rb
Method calculate_week_meeting_dates
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
def calculate_week_meeting_dates
meetings = []
@timeline_week_count.times do |wk|
week_start = @beginning_of_first_week + wk.weeks
# This excludes Sunday, putting the end of the week at Saturday.
- 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
Use with_index
to remove redundant each
. Open
Open
@course.weekdays.each_char.each_with_index do |w, i|
- Read upRead up
- Exclude checks
Checks for redundant each
.
Safety:
This cop is unsafe, as it can produce false positives if the receiver
is not an Enumerator
.
Example:
# bad
array.each.each { |v| do_something(v) }
# good
array.each { |v| do_something(v) }
# bad
array.each.each_with_index { |v, i| do_something(v, i) }
# good
array.each.with_index { |v, i| do_something(v, i) }
array.each_with_index { |v, i| do_something(v, i) }
# bad
array.each.each_with_object { |v, o| do_something(v, o) }
# good
array.each.with_object { |v, o| do_something(v, o) }
array.each_with_object { |v, o| do_something(v, o) }