Showing 91 of 91 total issues
File application_helper.rb
has 384 lines of code (exceeds 250 allowed). Consider refactoring. Open
module ApplicationHelper
def tabs(tabs = nil)
tabs ||= controller_path.match?(/admin/) ? FatFreeCRM::Tabs.admin : FatFreeCRM::Tabs.main
if tabs
@current_tab ||= tabs.first[:text] # Select first tab by default.
Method get_list_of_records
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
def get_list_of_records(options = {})
options[:query] ||= params[:query] if params[:query]
self.current_page = options[:page] if options[:page]
query, tags = parse_query_and_tags(options[:query])
self.current_query = query
- 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
Class ApplicationController
has 26 methods (exceeds 20 allowed). Consider refactoring. Open
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :configure_devise_parameters, if: :devise_controller?
before_action :authenticate_user!
Class EntitiesController
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
class EntitiesController < ApplicationController
before_action :set_current_tab, only: %i[index show]
before_action :set_view, only: %i[index show redraw]
before_action :set_options, only: :index
Method create_for
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def self.create_for(model, account, opportunity, params)
attributes = {
lead_id: model.id,
user_id: params[:account][:user_id] || account.user_id,
assigned_to: params[:account][:assigned_to],
- 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 task_summary
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def task_summary(task)
summary = [task.category.blank? ? t(:other) : t(task.category)]
if @view != "completed"
if @view == "pending" && task.user != current_user
summary << t(:task_from, task.user.full_name)
- 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 create
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def create
@comment_body = params[:comment_body]
respond_with(@opportunity) do |_format|
if @opportunity.save_with_account_and_permissions(params.permit!)
@opportunity.add_comment_by_user(@comment_body, current_user)
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
def redraw
current_user.pref[:contacts_per_page] = per_page_param if per_page_param
# Sorting and naming only: set the same option for Leads if the hasn't been set yet.
if params[:sort_by]
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 79.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
def redraw
current_user.pref[:leads_per_page] = per_page_param if per_page_param
# Sorting and naming only: set the same option for Contacts if the hasn't been set yet.
if params[:sort_by]
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 79.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Method timeline
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def timeline
state = params[:state].to_s
if %w[Collapsed Expanded].include?(state)
if (model_type = params[:type].to_s).present?
if %w[comment email].include?(model_type)
- 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 view_buttons
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def view_buttons
views = FatFreeCRM::ViewFactory.views_for(controller: controller.controller_name,
action: show_or_index_action)
return nil unless views.size > 1
- 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 respond_to_destroy
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def respond_to_destroy(method)
if method == :ajax
if called_from_index_page?
get_data_for_sidebar
@opportunities = get_opportunities
- 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 links_to_export
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def links_to_export(action = :index)
token = current_user.authentication_token
url_params = { action: action }
url_params[:id] = params[:id] unless params[:id].blank?
url_params[:query] = params[:query] unless params[:query].blank?
- 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 create
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def create
@comment_body = params[:comment_body]
respond_with(@contact) do |_format|
if @contact.save_with_account_and_permissions(params.permit!)
@contact.add_comment_by_user(@comment_body, current_user)
- 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 respond_to_destroy
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def respond_to_destroy(method)
if method == :ajax
if called_from_index_page? # Called from Leads index.
get_data_for_sidebar
@leads = get_leads
- 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 opportunity_revenue_message
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def opportunity_revenue_message(opportunity, detailed = false)
msg = []
won_or_lost = %w[won lost].include?(opportunity.stage)
msg << content_tag(:b, number_to_currency(opportunity.weighted_amount, precision: 0)) if opportunity.weighted_amount != 0
- 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 respond_to_destroy
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def respond_to_destroy(method)
if method == :ajax
if called_from_index_page?
@contacts = get_contacts
if @contacts.blank?
- 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 lead_summary
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def lead_summary(lead)
summary = []
summary << (lead.status ? t(lead.status) : t(:other))
if lead.company? && lead.title?
- 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 plain_text_body
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def plain_text_body(email)
# Extract all parts including nested
parts = if email.multipart?
email.parts.map { |p| p.multipart? ? p.parts : p }.flatten
else
- 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 attach
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def attach(email, asset, strip_first_line = false)
# If 'sent_to' email cannot be found, default to Dropbox email address
to = email.to.blank? ? @settings[:address] : email.to.join(", ")
cc = email.cc.blank? ? nil : email.cc.join(", ")