Method subscribe
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def subscribe(channel_name, last_sequence, params)
chan_sub = Server::ChannelSubscription.new(
channel_name,
@ws.env,
params: params,
Method message
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def message(event)
msg = parse_message(event)
if subscriptions = msg[:multiplex_subscribe]
subscriptions = [subscriptions] unless subscriptions.is_a?(Array)
- 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 subscribe_multiplexed
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def subscribe_multiplexed(subscriptions)
channels = subscriptions.map{|s| s[:channel]}
Firehose::Server.metrics.channels_subscribed_multiplexed_ws!(channels)
subscriptions.each do |sub|
- 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 ==
if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition. Open
if sub = @subscriptions[chan]
- Read upRead up
- Exclude checks
This cop checks for assignments in the conditions of if/while/until.
Example:
# bad
if some_var = true
do_something
end
Example:
# good
if some_var == true
do_something
end
Use ==
if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition. Open
if subscriptions = msg[:multiplex_subscribe]
- Read upRead up
- Exclude checks
This cop checks for assignments in the conditions of if/while/until.
Example:
# bad
if some_var = true
do_something
end
Example:
# good
if some_var == true
do_something
end
Useless assignment to variable - sequence
. Use _
or _sequence
as a variable name to indicate that it won't be used. Open
channel, sequence = sub[:channel]
- Read upRead up
- Exclude checks
This cop checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Unused method argument - event
. If it's necessary, use _
or _event
as an argument name to indicate that it won't be used. You can also write as close(*)
if you want the method to accept any arguments but don't care about them. Open
def close(event)
- Read upRead up
- Exclude checks
This cop checks for unused method arguments.
Example:
# bad
def some_method(used, unused, _unused_but_allowed)
puts used
end
Example:
# good
def some_method(used, _unused, _unused_but_allowed)
puts used
end
Unused method argument - event
. If it's necessary, use _
or _event
as an argument name to indicate that it won't be used. You can also write as open(*)
if you want the method to accept any arguments but don't care about them. Open
def open(event)
- Read upRead up
- Exclude checks
This cop checks for unused method arguments.
Example:
# bad
def some_method(used, unused, _unused_but_allowed)
puts used
end
Example:
# good
def some_method(used, _unused, _unused_but_allowed)
puts used
end
Use ==
if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition. Open
if channel_names = msg[:multiplex_unsubscribe]
- Read upRead up
- Exclude checks
This cop checks for assignments in the conditions of if/while/until.
Example:
# bad
if some_var = true
do_something
end
Example:
# good
if some_var == true
do_something
end
Unused method argument - event
. If it's necessary, use _
or _event
as an argument name to indicate that it won't be used. You can also write as open(*)
if you want the method to accept any arguments but don't care about them. Open
def open(event)
- Read upRead up
- Exclude checks
This cop checks for unused method arguments.
Example:
# bad
def some_method(used, unused, _unused_but_allowed)
puts used
end
Example:
# good
def some_method(used, _unused, _unused_but_allowed)
puts used
end