Showing 154 of 154 total issues
Function length
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
length: function(element, options) {
var CHECKS, blankOptions, check, fn, message, operator, tokenized_length, tokenizer;
tokenizer = options.js_tokenizer || "split('')";
tokenized_length = new Function('element', "return (element.val()." + tokenizer + " || '').length")(element);
CHECKS = {
Function addMetaTags
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
function addMetaTags(tagId, options) {
this._createMetaTag = function(name, content) {
var metaTag = jQuery("<meta>", {
name: name,
content: content
Function addMetaTags
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
function addMetaTags(tagId, options) {
this._createMetaTag = function(name, content) {
var metaTag = jQuery("<meta>", {
name: name,
content: content
Function addMetaTags
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
function addMetaTags(tagId, options) {
this._createMetaTag = function(name, content) {
var metaTag = jQuery("<meta>", {
name: name,
content: content
Identical blocks of code found in 2 locations. Consider refactoring. Open
def self.for_location(location)
location = LocationFormatter.new(location).format
return where(id: []) unless location
city = location.city
- 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 48.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
def self.for_location(location)
location = LocationFormatter.new(location).format
return where(id: []) unless location
city = location.city
- 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 48.
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 person_match_official?
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def person_match_official?(person, official)
return false unless district_or_office_for(person) ==
pvs_district_or_office_for(official)
return false unless NameComparison.new(comparable_family_name_for(person),
- 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 run
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def run(twitter_user)
data = twitter_user.as_json
data.each do |key, value|
case key
- 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 tab
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def tab(tab)
@governor = Governor.connected_to(@jurisdiction.abbreviation).active.first
@mayor = Mayor.connected_to(@jurisdiction.abbreviation).active.first ||
Councilmember.connected_to(@jurisdiction.abbreviation).active
.where(district: "Mayor").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 match_to_person
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def match_to_person
if person_id.present?
add_attributes_to(person)
return person
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 set_attributes_based_on_partner
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def set_attributes_based_on_partner
return unless referring_partner_info.present?
return if persisted?
self.password = Devise.friendly_token.first(6)
- 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_with_session
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def self.new_with_session(params, session)
super.tap do |user|
data = session['devise.facebook_data']
if data
user.email = data['info']['email'] if user.email.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
Avoid deeply nested control flow statements. Open
if ($(this).data('notLocallyUnique')) {
return $(this).removeData('notLocallyUnique').data('changed', true);
}
Method show
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def show
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
if resource.errors.empty?
set_flash_message(:notice, :confirmed) if is_navigational_format?
- 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 show
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def show
@blurb = Blurb.active.where(target_url: person_path(parent, resource)).first
@questions = resource.questions.in(needs_confirmation: [nil, false])
.includes(:user).desc(:created_at).page(params[:page])
tab "questions"
- 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 officials_by_state_and_office
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def officials_by_state_and_office(state_id, office_ids)
office_ids.each_with_index do |office_id, index|
begin
state_id = state_id == 'us' ? 'NA' : state_id.upcase
return get('Officials.getByOfficeState',
- 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 perform
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def perform(id)
question = Question.find(id)
user = question.user
if user && question.coordinates.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 office_ids
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def office_ids(options)
# Chairman, Councilmember
return [347, 368] if options[:state] == 'dc'
office_ids = []
- 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
Consider simplifying this complex logical expression. Open
return session if session_details[session].key?("type") && session_details[session]["type"] == type ||
type == "primary" && !session_details[session]["display_name"][/Budget|Called|Extraordinary|Fiscal|Special/] ||
type == "special" && session_details[session]["display_name"][/Budget|Called|Extraordinary|Fiscal|Special/]
Consider simplifying this complex logical expression. Open
if (width.blank? || height.blank?) ||
(opts[:state] && opts[:state] == Metadatum::Unaffiliated::ABBREVIATION) ||
api_key.blank? ||
Rails.env.development?