Showing 99 of 164 total issues
Method update
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
def update
before = { body: @post.body_markdown, title: @post.title, tags: @post.tags }
after_tags = if @post_type.has_category?
Tag.where(tag_set_id: @post.category.tag_set_id, name: params[:post][:tags_cache])
end
Class User
has 21 methods (exceeds 20 allowed). Consider refactoring. Open
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable,
Class ApplicationController
has 21 methods (exceeds 20 allowed). Consider refactoring. Open
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
Method create
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create
@post_type = PostType.find(params[:post][:post_type_id])
@parent = Post.where(id: params[:parent]).first
@category = if @post_type.has_category
if params[:post][:category_id].present?
Method recalc_privilege
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def recalc_privilege(internal_id, sandbox: false)
# Do not recalculate privileges already granted
return true if privilege?(internal_id, ignore_suspension: true, ignore_mod: true)
priv = Ability.where(internal_id: internal_id).first
- 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 posts
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
def posts(ids)
groups = ids.in_groups_of(100).map(&:compact)
posts = []
groups.each do |group|
posts = posts.concat request("https://api.stackexchange.com/2.2/posts/#{group.join(';')}",
Method codidact
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
def codidact
ad = Rails.cache.fetch 'codidact_ad', expires_in: 60.minutes do
ad = Image.new(600, 500)
ad.background_color = 'white'
Function gotoMenu
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
function gotoMenu(e) {
if (e.key === 'm') {
window.location.href = '/';
}
else if (e.key === 'u') {
Method qualifiers_to_sql
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
def qualifiers_to_sql(qualifiers)
valid_value = {
date: /^[<>=]{0,2}\d+(?:s|m|h|d|w|mo|y)?$/,
numeric: /^[<>=]{0,2}\d+$/
}
Method create
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create
@post = Post.find(params[:comment][:post_id])
if @post.comments_disabled && !current_user.is_moderator && !current_user.is_admin
render json: { status: 'failed', message: 'Comments have been disabled on this post.' }, status: :forbidden
return
Function toolsMenu
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
function toolsMenu(e) {
if (e.key === 'e') {
window.location.href = $(_CodidactKeyboard.selectedItem).find('.tools--item i.fa.fa-pencil-alt').parent().attr("href");
}
else if (e.key === 'h') {
Method do_xml_transform
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.do_xml_transform(site_domain, data_type, options)
dump_path = options.path
community_id = options.community
category_id = options.category
Method run
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run
# We only want questions and answers; nuke anything that isn't
query "DELETE FROM #{table 'posts'} WHERE #{column 'post_type_id'} NOT IN (1, 2)"
# Change post user IDs to SE account IDs so we can re-associate them with users later
Method mod_privilege_action
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def mod_privilege_action
ability = Ability.find_by internal_id: params[:ability]
return not_found if ability.internal_id == 'mod'
ua = @user.community_user.privilege(ability.internal_id)
- 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 mod_privilege_action
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
def mod_privilege_action
ability = Ability.find_by internal_id: params[:ability]
return not_found if ability.internal_id == 'mod'
ua = @user.community_user.privilege(ability.internal_id)
Method full_log
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def full_log
@posts = Post.where(user: @user).count
@comments = Comment.where(user: @user).count
@flags = Flag.where(user: @user).count
@suggested_edits = SuggestedEdit.where(user: @user).count
Function createNotification
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
createNotification: function(type, message) {
// Some messages include a date stamp, `append_date` governs that.
let append_date = false;
let message_with_date = message;
if (type === 'danger') {
Method close
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def close
unless check_your_privilege('flag_close', nil, false)
render json: { status: 'failed', message: helpers.ability_err_msg(:flag_close, 'close this post') },
status: :forbidden
return
Method tab
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def tab(text, link_url, **opts, &block)
active = opts[:is_active] || false
opts.delete :is_active
opts[:class] = if opts[:class]
"#{opts[:class]} tabs--tab#{active ? ' tab__active' : ''}"
- 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 do_xml_transform
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def self.do_xml_transform(site_domain, data_type, options)
dump_path = options.path
community_id = options.community
category_id = options.category
- 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"