Assignment Branch Condition size for analytics is too high. [39.67/15] Open
def self.analytics(request, location=nil)
if Goldencobra::Setting.for_key("goldencobra.analytics.active") == "true"
self.create! do |t|
t.utm_source = request.params["utm_source"]
t.utm_medium = request.params["utm_medium"]
- 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
Complex method Goldencobra::Tracking::analytics (57.1) Open
def self.analytics(request, location=nil)
if Goldencobra::Setting.for_key("goldencobra.analytics.active") == "true"
self.create! do |t|
t.utm_source = request.params["utm_source"]
t.utm_medium = request.params["utm_medium"]
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Method has too many lines. [21/10] Open
def self.analytics(request, location=nil)
if Goldencobra::Setting.for_key("goldencobra.analytics.active") == "true"
self.create! do |t|
t.utm_source = request.params["utm_source"]
t.utm_medium = request.params["utm_medium"]
- 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.
Goldencobra::Tracking#self.analytics has approx 15 statements Open
def self.analytics(request, location=nil)
- Read upRead up
- Exclude checks
A method with Too Many Statements
is any method that has a large number of lines.
Too Many Statements
warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements
counts +1 for every simple statement in a method and +1 for every statement within a control structure (if
, else
, case
, when
, for
, while
, until
, begin
, rescue
) but it doesn't count the control structure itself.
So the following method would score +6 in Reek's statement-counting algorithm:
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil # +1
end
opt = (val = parse_arg(val, &error))[1] # +2
val = conv_arg(*val) # +3
if opt and !arg
argv.shift # +4
else
val[0] = nil # +5
end
val # +6
end
(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)
Method analytics
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def self.analytics(request, location=nil)
if Goldencobra::Setting.for_key("goldencobra.analytics.active") == "true"
self.create! do |t|
t.utm_source = request.params["utm_source"]
t.utm_medium = request.params["utm_medium"]
- 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
Goldencobra::Tracking#self.analytics calls 'request.env' 4 times Open
t.language = request.env["HTTP_ACCEPT_LANGUAGE"]
t.user_agent = request.env["HTTP_USER_AGENT"]
if request.session_options[:id].present?
t.session_id = request.session_options[:id]
else
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::Tracking has no descriptive comment Open
class Tracking < ActiveRecord::Base
- Read upRead up
- Exclude checks
Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.
Example
Given
class Dummy
# Do things...
end
Reek would emit the following warning:
test.rb -- 1 warning:
[1]:Dummy has no descriptive comment (IrresponsibleModule)
Fixing this is simple - just an explaining comment:
# The Dummy class is responsible for ...
class Dummy
# Do things...
end
Goldencobra::Tracking#self.analytics calls 'request.session_options' 2 times Open
if request.session_options[:id].present?
t.session_id = request.session_options[:id]
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::Tracking#self.analytics calls 'request.session_options[:id]' 2 times Open
if request.session_options[:id].present?
t.session_id = request.session_options[:id]
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::Tracking#self.analytics calls 'request.params' 7 times Open
t.utm_source = request.params["utm_source"]
t.utm_medium = request.params["utm_medium"]
t.utm_term = request.params["utm_term"]
t.utm_content = request.params["utm_content"]
t.utm_campaign = request.params["utm_campaign"]
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::Tracking#self.analytics calls 'request.env['REMOTE_ADDR']' 2 times Open
t.session_id = "FB" + Digest::MD5.hexdigest("#{request.env['REMOTE_ADDR']}#{Time.now.to_f}")
end
t.referer = request.referer
t.url = request.url
t.ip = request.env['REMOTE_ADDR']
- Read upRead up
- Exclude checks
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Reek implements a check for Duplicate Method Call.
Example
Here's a very much simplified and contrived example. The following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
One quick approach to silence Reek would be to refactor the code thus:
def double_thing()
thing = @other.thing
thing + thing
end
A slightly different approach would be to replace all calls of double_thing
by calls to @other.double_thing
:
class Other
def double_thing()
thing + thing
end
end
The approach you take will depend on balancing other factors in your code.
Goldencobra::Tracking#self.analytics has the variable name 't' Open
self.create! do |t|
- Read upRead up
- Exclude checks
An Uncommunicative Variable Name
is a variable name that doesn't communicate its intent well enough.
Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.
Add an empty line after magic comments. Open
# == Schema Information
- Read upRead up
- Exclude checks
Checks for a newline after the final magic comment.
Example:
# good
# frozen_string_literal: true
# Some documentation for Person
class Person
# Some code
end
# bad
# frozen_string_literal: true
# Some documentation for Person
class Person
# Some code
end
Prefer double-quoted strings inside interpolations. Open
t.session_id = "FB" + Digest::MD5.hexdigest("#{request.env['REMOTE_ADDR']}#{Time.now.to_f}")
- Read upRead up
- Exclude checks
This cop checks that quotes inside the string interpolation match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
result = "Tests #{success ? "PASS" : "FAIL"}"
# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"
Example: EnforcedStyle: double_quotes
# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"
# good
result = "Tests #{success ? "PASS" : "FAIL"}"
Missing top-level class documentation comment. Open
class Tracking < ActiveRecord::Base
- Read upRead up
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Open
t.ip = request.env['REMOTE_ADDR']
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
Unnecessary utf-8 encoding comment. Open
# encoding: utf-8
- Read upRead up
- Exclude checks
This cop checks ensures source files have no utf-8 encoding comments.
Example:
# bad
# encoding: UTF-8
# coding: UTF-8
# -*- coding: UTF-8 -*-
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if Goldencobra::Setting.for_key("goldencobra.analytics.active") == "true"
- 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
Line is too long. [104/100] Open
t.session_id = "FB" + Digest::MD5.hexdigest("#{request.env['REMOTE_ADDR']}#{Time.now.to_f}")
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Use compact module/class definition instead of nested style. Open
module Goldencobra
- Read upRead up
- Exclude checks
This cop checks the style of children definitions at classes and modules. Basically there are two different styles:
Example: EnforcedStyle: nested (default)
# good
# have each child on its own line
class Foo
class Bar
end
end
Example: EnforcedStyle: compact
# good
# combine definitions as much as possible
class Foo::Bar
end
The compact style is only forced for classes/modules with one child.
Use the return of the conditional for variable assignment and comparison. Open
if request.session_options[:id].present?
t.session_id = request.session_options[:id]
else
t.session_id = "FB" + Digest::MD5.hexdigest("#{request.env['REMOTE_ADDR']}#{Time.now.to_f}")
end
- Exclude checks
Missing space after #
. Open
#http://localhost:4000/?utm_source=quelle&utm_medium=medium&utm_term=begriff&utm_content=content&utm_campaign=name
- Read upRead up
- Exclude checks
This cop checks whether comments have a leading space after the
#
denoting the start of the comment. The leading space is not
required for some RDoc special syntax, like #++
, #--
,
#:nodoc
, =begin
- and =end
comments, "shebang" directives,
or rackup options.
Example:
# bad
#Some comment
# good
# Some comment
Surrounding space missing in default value assignment. Open
def self.analytics(request, location=nil)
- Read upRead up
- Exclude checks
Checks that the equals signs in parameter default assignments have or don't have surrounding space depending on configuration.
Example: EnforcedStyle: space (default)
# bad
def some_method(arg1=:default, arg2=nil, arg3=[])
# do something...
end
# good
def some_method(arg1 = :default, arg2 = nil, arg3 = [])
# do something...
end
Example: EnforcedStyle: no_space
# bad
def some_method(arg1 = :default, arg2 = nil, arg3 = [])
# do something...
end
# good
def some_method(arg1=:default, arg2=nil, arg3=[])
# do something...
end
Redundant self
detected. Open
self.create! do |t|
- Read upRead up
- Exclude checks
This cop checks for redundant uses of self
.
The usage of self
is only needed when:
Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.
Calling an attribute writer to prevent an local variable assignment.
Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.
Note we allow uses of self
with operators because it would be awkward
otherwise.
Example:
# bad
def foo(bar)
self.baz
end
# good
def foo(bar)
self.bar # Resolves name clash with the argument.
end
def foo
bar = 1
self.bar # Resolves name clash with the local variable.
end
def foo
%w[x y z].select do |bar|
self.bar == bar # Resolves name clash with argument of the block.
end
end