Showing 167 of 167 total issues
Identical blocks of code found in 2 locations. Consider refactoring. Open
if !@impound_claim.submitting?
flash[:error] = if @impound_claim.responded?
"That claim has already been responded to"
else
"That claim hasn't been submitted yet (it's #{@impound_claim.status_humanized})"
- 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 82.
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
Function BinxAdminBlogs
has 57 lines of code (exceeds 50 allowed). Consider refactoring. Open
function BinxAdminBlogs() {
return {
init() {
this.initializeBlogInfoToggling();
this.initializePrimaryPhotoFunctionality();
Method create
has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring. Open
def create
@feedback = Feedback.new(permitted_parameters)
@feedback.user_id = current_user.id if current_user.present?
return true if block_the_spam(@feedback)
- 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 missing_manufacturer_bikes
has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring. Open
def missing_manufacturer_bikes
session.delete(:missing_manufacturer_time_order) if params[:reset_view].present?
if params[:search_time_ordered].present?
session[:missing_manufacturer_time_order] = InputNormalizer.boolean(params[:search_time_ordered])
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 update
has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring. Open
def update
if params[:force_merge_email].present?
force_merge_users(params[:force_merge_email])
else
@user.name = params[:user][: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 update
has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring. Open
def update
@organization = Organization.friendly_find(params[:id])
if @organization.blank?
redirect_to(api_v1_not_found_url) && return
elsif params[:access_token] == @organization.access_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 calculated_pos_kind
has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring. Open
def self.calculated_pos_kind(organization)
return organization.manual_pos_kind if organization.manual_pos_kind.present?
bikes = organization.created_bikes # NOTE: Only created, so regional orgs don't get them
recent_bikes = bikes.where(created_at: (Time.current - 1.week)..Time.current)
if organization.ascend_name.present? || recent_bikes.ascend_pos.count > 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
Function localizedDateText
has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring. Open
localizedDateText (
time,
singleFormat,
preciseTime,
includeSeconds,
- 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 update
has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring. Open
def update
if !@impound_claim.submitting?
flash[:error] = if @impound_claim.responded?
"That claim has already been responded to"
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 update
has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring. Open
def update
if !@impound_claim.submitting?
flash[:error] = if @impound_claim.responded?
"That claim has already been responded to"
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
Function init
has 56 lines of code (exceeds 50 allowed). Consider refactoring. Open
init () {
this.initAdminSearchSelect()
this.initBikeTabs()
// Enable utilities
Method states
has 54 lines of code (exceeds 50 allowed). Consider refactoring. Open
def states
[
{name: "Alabama", abbr: "AL"},
{name: "Alaska", abbr: "AK"},
{name: "Arizona", abbr: "AZ"},
Method parse
has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring. Open
def self.parse(payload, sso_secret = nil)
sso = new
sso.sso_secret = sso_secret if sso_secret
parsed = Rack::Utils.parse_query(payload)
- 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_period
has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring. Open
def set_period
@timezone ||= Time.zone
# Set time period
@period ||= params[:period]
if @period == "custom"
- 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 matching_user_alerts
has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring. Open
def matching_user_alerts
user_alerts = UserAlert
if UserAlert.kinds.include?(params[:search_kind])
@kind = params[:search_kind]
user_alerts = user_alerts.where(kind: @kind)
- 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 15 (exceeds 10 allowed). Consider refactoring. Open
def perform(bike_id)
bike = Bike.unscoped.where(id: bike_id).first
if bike.present?
bb_data = BikeBookIntegration.new.get_model(bike)
- 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
Function exports
has 51 lines of code (exceeds 50 allowed). Consider refactoring. Open
module.exports = function (api) {
var validEnv = ['development', 'test', 'production']
var currentEnv = api.env()
var isDevelopmentEnv = api.env('development')
var isProductionEnv = api.env('production')
Method set_location_info
has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring. Open
def set_location_info
if current_stolen_record.present?
# If there is a current stolen - even if it has a blank location - use it
# It's used for searching and displaying stolen bikes, we don't want other information leaking
self.attributes = if address_set_manually # Only set coordinates if the address is set manually
- 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 build_bike_status
has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring. Open
def build_bike_status
self.max_char = compute_max_char
location = ""
if !close_twitter_accounts&.first&.default? && neighborhood.present?
- 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 available_graduated_notifications
has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring. Open
def available_graduated_notifications
return @available_graduated_notifications if defined?(@available_graduated_notifications)
if params[:search_status] == "all"
@search_status = "all"
a_graduated_notifications = graduated_notifications
- 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"