app/models/drug.rb
Class Drug
has 21 methods (exceeds 20 allowed). Consider refactoring. Open
Open
class Drug < ApplicationRecord
has_one :dose_info
def self.find_with_aliases(name)
name = name&.downcase
Method test_results
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
Open
def test_results
test_result_string = ''
test_result_string += "Marquis test: #{marquis_test}. " if marquis_test
test_result_string += "Mandelin test: #{mandelin_test}. " if mandelin_test
test_result_string += "Mecke test: #{mecke_test}. " if mecke_test
- 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
Specify a :dependent
option. Open
Open
has_one :dose_info
- Read upRead up
- Exclude checks
This cop looks for has_many
or has_one
associations that don't
specify a :dependent
option.
It doesn't register an offense if :through
option was specified.
Example:
# bad
class User < ActiveRecord::Base
has_many :comments
has_one :avatar
end
# good
class User < ActiveRecord::Base
has_many :comments, dependent: :restrict_with_exception
has_one :avatar, dependent: :destroy
has_many :patients, through: :appointments
end
Re-enable Metrics/CyclomaticComplexity cop with # rubocop:enable
after disabling it. Open
Open
# rubocop:disable Metrics/CyclomaticComplexity
- Exclude checks
Re-enable Metrics/PerceivedComplexity cop with # rubocop:enable
after disabling it. Open
Open
# rubocop:disable Metrics/PerceivedComplexity
- Exclude checks
Re-enable Metrics/MethodLength cop with # rubocop:enable
after disabling it. Open
Open
# rubocop:disable Metrics/MethodLength
- Exclude checks
Re-enable Metrics/AbcSize cop with # rubocop:enable
after disabling it. Open
Open
# rubocop:disable Metrics/AbcSize
- Exclude checks