Showing 5 of 15 total issues
Class User
has 32 methods (exceeds 20 allowed). Consider refactoring. Open
Open
class User < ActiveRecord::Base
include Models::Todolistable
delegate :token, to: :account_token
Method initialize
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
def initialize(user)
# simple authorization like self.current_user = User.first
can :create, :sessions if development?
can :show, :sitemap
Method find_or_create_by_omniauth
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
Open
def self.find_or_create_by_omniauth(omniauth)
token = omniauth['credentials']['token']
ActiveRecord::Base.transaction do
find_by_github_id(omniauth['uid']) || create! do |account|
account.token = token
- 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 safe_replace
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
def safe_replace
# extract replaceable tags
replaceable = {}
REPLACEABLE_TAGS.each do |tag|
@html.gsub!(%r{<#{tag}>.*?</#{tag}>}m) do |match|
Method show
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
def show
if @tag = Tag.find_by_name(params[:id])
redirect_to @tag.entity if @tag.alias?
@posts = Post.not_private.tagged_with(@tag.name).page(params[:page])
- 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"