Class has too many lines. [271/250] Open
class Company < ActiveRecord::Base
include Concerns::Cacheable
include ActionView::Helpers::NumberHelper
include Concerns::AttributeArrayable
include Concerns::Domainable
- Read upRead up
- Create a ticketCreate a ticket
- 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.
Class Company
has 46 methods (exceeds 20 allowed). Consider refactoring. Open
class Company < ActiveRecord::Base
include Concerns::Cacheable
include ActionView::Helpers::NumberHelper
include Concerns::AttributeArrayable
include Concerns::Domainable
- Create a ticketCreate a ticket
File company.rb
has 273 lines of code (exceeds 250 allowed). Consider refactoring. Open
class Company < ActiveRecord::Base
include Concerns::Cacheable
include ActionView::Helpers::NumberHelper
include Concerns::AttributeArrayable
include Concerns::Domainable
- Create a ticketCreate a ticket
Cyclomatic complexity for set_capital_fields! is too high. [7/6] Open
def set_capital_fields!
self.capital_raised = [crunchbase_org(5).total_funding.to_i || 0, funded? ? 20_000 : 0].max
if crunchbase_org.acquisition.present?
self.acquisition_date = Date.parse(crunchbase_org.acquisition.announced_on) rescue nil
end
- Read upRead up
- Create a ticketCreate a ticket
- 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.
Method as_json_api
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def as_json_api(options = {})
options.reverse_merge!(
methods: [:competitors],
only: [
:id,
- Create a ticketCreate a ticket
Method set_capital_fields!
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def set_capital_fields!
self.capital_raised = [crunchbase_org(5).total_funding.to_i || 0, funded? ? 20_000 : 0].max
if crunchbase_org.acquisition.present?
self.acquisition_date = Date.parse(crunchbase_org.acquisition.announced_on) rescue nil
end
- Read upRead up
- Create a ticketCreate a ticket
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 set_angelist_attributes!
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def set_angelist_attributes!(timeout: 5)
startup = angelist_startup(timeout)
return unless startup.found?
self.al_id = startup.id
self.domain ||= startup.url
- Read upRead up
- Create a ticketCreate a ticket
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 set_crunchbase_attributes!
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def set_crunchbase_attributes!(timeout: 5)
org = crunchbase_org(timeout)
return unless org.found?
self.name ||= org.name
self.crunchbase_id = org.permalink
- Read upRead up
- Create a ticketCreate a ticket
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 add_founder_graph_relationship!
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def add_founder_graph_relationship!
return unless founders.count > 1
founders.each do |f1|
founders.each do |f2|
f1.connect_to! f2, :cofound unless f1.id == f2.id
- Read upRead up
- Create a ticketCreate a ticket
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 add_investor_graph_relationship!
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def add_investor_graph_relationship!
partners = investments.where.not(investor: nil)
return unless partners.count > 1
partners.each do |i1|
partners.each do |i2|
- Read upRead up
- Create a ticketCreate a ticket
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 delete
instead of gsub
. Open
name.gsub(' ', '').parameterize
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop identifies places where gsub
can be replaced by
tr
or delete
.
Example:
# bad
'abc'.gsub('b', 'd')
'abc'.gsub('a', '')
'abc'.gsub(/a/, 'd')
'abc'.gsub!('a', 'd')
# good
'abc'.gsub(/.*/, 'a')
'abc'.gsub(/a+/, 'd')
'abc'.tr('b', 'd')
'a b c'.delete(' ')