Class has too many lines. [228/150] Open
class Subscription
include Observable
RENEW_HANDICAP = 60
- Read upRead up
- Exclude checks
This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for _subscribe_at_pubnub is too high. [47.19/30] Open
def _subscribe_at_pubnub
raise 'Subscription is not alive' unless alive?
s_key = @_subscription['deliveryMode']['subscriberKey']
- 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. [26/15] Open
def _subscribe_at_pubnub
raise 'Subscription is not alive' unless alive?
s_key = @_subscription['deliveryMode']['subscriberKey']
- 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 has too many lines. [26/15] Open
def subscribe(events = nil)
set_events(events) if events.is_a? Array
raise 'Events are undefined' unless @event_filters.is_a?(Array) && !@event_filters.empty?
- 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.
Class Subscription
has 23 methods (exceeds 20 allowed). Consider refactoring. Open
class Subscription
include Observable
RENEW_HANDICAP = 60
Method has too many lines. [20/15] Open
def renew(events = nil)
set_events(events) if events.is_a? Array
raise 'Subscription is not alive' unless alive?
raise 'Events are undefined' if @event_filters.empty?
- 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 alive? is too high. [8/6] Open
def alive?
s = @_subscription
if
(s.key?('deliveryMode') && s['deliveryMode']) \
&& (s['deliveryMode'].key?('subscriberKey') && s['deliveryMode']['subscriberKey']) \
- 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 alive? is too high. [8/7] Open
def alive?
s = @_subscription
if
(s.key?('deliveryMode') && s['deliveryMode']) \
&& (s['deliveryMode'].key?('subscriberKey') && s['deliveryMode']['subscriberKey']) \
- 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
Method has too many lines. [16/15] Open
def nil_subscription
{
'eventFilters' => [],
'expirationTime' => '', # 2014-03-12T19:54:35.613Z
'expiresIn' => 0,
- 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 subscribe
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def subscribe(events = nil)
set_events(events) if events.is_a? Array
raise 'Events are undefined' unless @event_filters.is_a?(Array) && !@event_filters.empty?
Method _subscribe_at_pubnub
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def _subscribe_at_pubnub
raise 'Subscription is not alive' unless alive?
s_key = @_subscription['deliveryMode']['subscriberKey']
Consider simplifying this complex logical expression. Open
if
(s.key?('deliveryMode') && s['deliveryMode']) \
&& (s['deliveryMode'].key?('subscriberKey') && s['deliveryMode']['subscriberKey']) \
&& (
s['deliveryMode'].key?('address') \
Place the condition on the same line as if
. Open
(s.key?('deliveryMode') && s['deliveryMode']) \
&& (s['deliveryMode'].key?('subscriberKey') && s['deliveryMode']['subscriberKey']) \
&& (
s['deliveryMode'].key?('address') \
&& !s['deliveryMode']['address'].nil? \
- Read upRead up
- Exclude checks
This cop checks for conditions that are not on the same line as if/while/until.
Example:
# bad
if
some_condition
do_something
end
Example:
# good
if some_condition
do_something
end
Unused method argument - ssl_on
. If it's necessary, use _
or _ssl_on
as an argument name to indicate that it won't be used. Open
def new_pubnub(subscribe_key = '', ssl_on = false, publish_key = '', my_logger = nil)
- 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
Do not prefix writer method names with set_
. Open
def set_events(events)
- Read upRead up
- Exclude checks
This cop makes sure that accessor methods are named properly.
Example:
# bad
def set_attribute(value)
end
# good
def attribute=(value)
end
# bad
def get_attribute
end
# good
def attribute
end
Unused method argument - my_logger
. If it's necessary, use _
or _my_logger
as an argument name to indicate that it won't be used. Open
def new_pubnub(subscribe_key = '', ssl_on = false, publish_key = '', my_logger = nil)
- 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
Favor modifier unless
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
. Open
unless alive?
- Read upRead up
- Exclude checks
Checks for if and unless statements that would fit on one line
if written as a modifier if/unless. The maximum line length is
configured in the Metrics/LineLength
cop.
Example:
# bad
if condition
do_stuff(bar)
end
unless qux.empty?
Foo.do_something
end
# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?
Trailing whitespace detected. Open
- Exclude checks
Do not prefix writer method names with set_
. Open
def set_subscription(data)
- Read upRead up
- Exclude checks
This cop makes sure that accessor methods are named properly.
Example:
# bad
def set_attribute(value)
end
# good
def attribute=(value)
end
# bad
def get_attribute
end
# good
def attribute
end
Use the lambda
method for multiline lambdas. Open
presence: ->(envelope) {
- Read upRead up
- Exclude checks
This cop (by default) checks for uses of the lambda literal syntax for single line lambdas, and the method call syntax for multiline lambdas. It is configurable to enforce one of the styles for both single line and multiline lambdas as well.
Example: EnforcedStyle: linecountdependent (default)
# bad
f = lambda { |x| x }
f = ->(x) do
x
end
# good
f = ->(x) { x }
f = lambda do |x|
x
end
Example: EnforcedStyle: lambda
# bad
f = ->(x) { x }
f = ->(x) do
x
end
# good
f = lambda { |x| x }
f = lambda do |x|
x
end
Example: EnforcedStyle: literal
# bad
f = lambda { |x| x }
f = lambda do |x|
x
end
# good
f = ->(x) { x }
f = ->(x) do
x
end
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if @_pubnub && alive?
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Use the lambda
method for multiline lambdas. Open
message: ->(envelope) {
- Read upRead up
- Exclude checks
This cop (by default) checks for uses of the lambda literal syntax for single line lambdas, and the method call syntax for multiline lambdas. It is configurable to enforce one of the styles for both single line and multiline lambdas as well.
Example: EnforcedStyle: linecountdependent (default)
# bad
f = lambda { |x| x }
f = ->(x) do
x
end
# good
f = ->(x) { x }
f = lambda do |x|
x
end
Example: EnforcedStyle: lambda
# bad
f = ->(x) { x }
f = ->(x) do
x
end
# good
f = lambda { |x| x }
f = lambda do |x|
x
end
Example: EnforcedStyle: literal
# bad
f = lambda { |x| x }
f = lambda do |x|
x
end
# good
f = ->(x) { x }
f = ->(x) do
x
end
Use (envelope.status[:last_timetoken]).zero?
instead of envelope.status[:last_timetoken] == 0
. Open
elsif envelope.status[:last_timetoken] == 0 # Connected!
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0