File cms_controller.rb
has 568 lines of code (exceeds 250 allowed). Consider refactoring. Open
class CmsController < MyProfileController
protect "edit_profile", :profile, only: [:set_home_page]
include ArticleHelper
include CategoriesHelper
Class CmsController
has 40 methods (exceeds 20 allowed). Consider refactoring. Open
class CmsController < MyProfileController
protect "edit_profile", :profile, only: [:set_home_page]
include ArticleHelper
include CategoriesHelper
Method edit
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
def edit
params[:article] ||= {}
@success_back_to = params[:success_back_to]
@article = profile.articles.find(params[:id])
version = params[:version]
- 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 new
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
def new
# FIXME this method should share some logic with edit !!!
@success_back_to = params[:success_back_to]
# user must choose an article type 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 publish_on_communities
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
def publish_on_communities
if request.post?
@back_to = params[:back_to]
@article = profile.articles.find(params[:id])
@failed = {}
- 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 upload_files
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def upload_files
upload_single_file?
@uploaded_files = []
@parent = check_parent(params[:parent_id])
@target = @parent ? ("/%s/%s" % [profile.identifier, @parent.full_name]) : "/%s" % profile.identifier
- 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 new
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
def new
# FIXME this method should share some logic with edit !!!
@success_back_to = params[:success_back_to]
# user must choose an article type first
Method invite_to_event
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def invite_to_event
@article = profile.articles.find(params[:id])
@profiles = invite_event_to @article
record_coming
if request.post?
- 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 publish_on_portal_community
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def publish_on_portal_community
if request.post?
@article = profile.articles.find(params[:id])
if environment.portal_enabled
task = ApproveArticle.create!(article: @article, name: params[:name], target: environment.portal_community, requestor: 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 publish
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def publish
@article = profile.articles.find(params[:id])
record_coming
@failed = {}
if request.post?
- 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 edit
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
def edit
params[:article] ||= {}
@success_back_to = params[:success_back_to]
@article = profile.articles.find(params[:id])
version = params[:version]
Method invite_to_event
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def invite_to_event
@article = profile.articles.find(params[:id])
@profiles = invite_event_to @article
record_coming
if request.post?
Method upload_files
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def upload_files
upload_single_file?
@uploaded_files = []
@parent = check_parent(params[:parent_id])
@target = @parent ? ("/%s/%s" % [profile.identifier, @parent.full_name]) : "/%s" % profile.identifier
Method publish_on_communities
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def publish_on_communities
if request.post?
@back_to = params[:back_to]
@article = profile.articles.find(params[:id])
@failed = {}
Method media_upload
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def media_upload
parent = check_parent(params[:parent_id])
if request.post?
begin
file = params[:file].present? ? params[:file] : params[:crop][:file]
- 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 destroy
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def destroy
@article = profile.articles.find(params[:id])
if request.post?
@article.destroy
session[:notice] = _("\"%s\" was removed." % @article.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
Avoid deeply nested control flow statements. Open
redirect_to action: (@article.parent ? "view" : "index"), id: @article.parent
Method select_profile
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def select_profile
current_page = params[:page] ? Article.find(params[:page]) : nil
@sensitive_back = params[:back] ? params[:back] : false
- 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 set_home_page
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def set_home_page
return render_access_denied unless user.can_change_homepage?
article = (params[:id].nil? || params[:id].blank?) ? nil : profile.articles.find(params[:id])
profile.update_attribute(:home_page, article)
- 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 suggest_an_article
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def suggest_an_article
@back_to = params[:back_to] || request.referer || url_for(profile.public_profile_url)
@task = SuggestArticle.new(params[:task])
if request.post?
@task.target = profile
- 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 article_list_to_json
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def article_list_to_json(list)
list.map do |item|
{
"title" => item.title,
"url" => item.image? ? item.public_filename(:uploaded) : url_for(item.url),
- 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 invite_event_to
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def invite_event_to(article)
profiles = profile.kind_of?(Organization) ? profile.members : profile.friends
inviteds = article.invitations if article.event?
result = []
profiles.each do |profile|
- 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 load_recent_files
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def load_recent_files(parent_id = nil, q = nil, paginate_options = { page: 1, per_page: 6 })
# TODO Since we only have special support for images, I'm limiting myself to
# consider generic files as non-images. In the future, with more supported
# file types we'll need to have a smart way to fetch from the database
# scopes of each supported type as well as the non-supported types as a
- 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 sensitive_content
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def sensitive_content
current_page = params[:page] ? Article.find(params[:page]) : nil
select_subdirectory = !params[:select_subdirectory].nil?
@sensitive_back = params[:not_back] ? (params[:not_back] == "true") : false
- 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
if @failed.blank?
session[:notice] = _("Your publish request was sent successfully")
if @back_to
redirect_to @back_to
else
- 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 26.
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
if @failed.blank?
session[:notice] = _("Your friends were invited successfully.")
if @back_to
redirect_to @back_to
else
- 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 26.
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