Showing 4 of 6 total issues
Class Question
has 23 methods (exceeds 20 allowed). Consider refactoring. Open
class Question < ActiveRecord::Base
include VotesCounter
include ZhishiDateHelper
include Searchable
include ModelJSONHashHelper
Method method_missing
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def method_missing(method_name, *args, &block)
if resource_match = method_name.to_s.match(/\A(?<from_resource>\w+)_to_(?<to_resource>\w+)\z/)
from_resource, to_resource = [resource_match[:from_resource], resource_match[:to_resource]].map do |resource_type|
resource_type.singularize.camelize.constantize rescue nil
end
- 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 evaluate_reward
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def evaluate_reward(new_vote, value, subject)
key = subject.name.underscore
reward = 0
if new_vote
reward = REWARD["#{key}_upvote"] if value == 1 #upvote
- 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 authenticated?
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def authenticated?
if request.headers['Authorization']
strategy, token = request.headers['Authorization'].split
auth = AndelaAuthV2.authenticate(token)
if strategy == 'Bearer' && auth.authenticated?
- 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"