Showing 67 of 67 total issues
File rails.validations.js
has 622 lines of code (exceeds 250 allowed). Consider refactoring. Open
(function() {
var $, validateElement, validateForm, validatorsFor,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
$ = jQuery;
Consider simplifying this complex logical expression. Open
return false if !response_field.field_options["required"] || # field is not required
(response && response.upload?) || # file has been uploaded
(value && !value.blank? && !value.is_a?(Hash)) || # value isn't blank (ignore hashes)
(response_field.field_type.in?(ResponseField::OPTIONS_FIELDS) && (response_field.field_options["options"] || []).empty?) ||
response_field.field_type == "checkboxes" && value && value.reject{|k, v| !v}.length > 0 || # required checkboxes have at least one checkbox checked
Method add_params_to_query
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
def self.add_params_to_query(query, params, args = {})
if args[:vendor_searching]
if !params[:q].blank?
query = query.full_search_vendor(params[:q])
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (_ref = element.val(), __indexOf.call((function() {
var _i, _len, _ref1, _results;
_ref1 = options["in"];
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
- 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 134.
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 (_ref = element.val(), __indexOf.call((function() {
var _i, _len, _ref1, _results;
_ref1 = options["in"];
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
- 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 134.
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
Class User
has 26 methods (exceeds 20 allowed). Consider refactoring. Open
class User < ActiveRecord::Base
include Clearance::User
attr_accessor :is_inviting
attr_accessor :is_admining
Function input
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
input: function(input) {
var $form, $input, binding, event, form, _ref;
$input = $(input);
form = input.form;
$form = $(form);
Method serialized
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def serialized(*args)
obj = args[0]
is_collection = obj.respond_to?(:each)
if args[1].is_a?(Hash)
- 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 uniqueness
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
uniqueness: function(element, options) {
var data, key, message, name, scope_value, scoped_element, scoped_name, _ref;
message = ClientSideValidations.validators.local.presence(element, options);
if (message) {
if (options.allow_blank === true) {
Method calculate_sortable_value
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def calculate_sortable_value
self.sortable_value = case response_field.field_type
when "date"
['year', 'month', 'day'].each { |x| return 0 unless value[x] && !value[x].blank? }
DateTime.new(value['year'].to_i, value['month'].to_i, value['day'].to_i).to_i rescue 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 initialize
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
def initialize(user)
can :read, Project do |project|
project.posted_at
end
Method add_params_to_query
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.add_params_to_query(query, params, args = {})
if args[:vendor_searching]
if !params[:q].blank?
query = query.full_search_vendor(params[:q])
end
Function numericality
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
numericality: function(element, options) {
var CHECKS, check, check_value, fn, form, operator, val;
val = jQuery.trim(element.val());
if (!ClientSideValidations.patterns.numericality.test(val)) {
if (options.allow_blank === true && this.presence(element, {
Method required_field
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def required_field(response_field, response, value)
return false if !response_field.field_options["required"] || # field is not required
(response && response.upload?) || # file has been uploaded
(value && !value.blank? && !value.is_a?(Hash)) || # value isn't blank (ignore hashes)
(response_field.field_type.in?(ResponseField::OPTIONS_FIELDS) && (response_field.field_options["options"] || []).empty?) ||
- 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 form
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
form: function(form) {
var $form, binding, event, _ref;
$form = $(form);
form.ClientSideValidations = {
settings: window.ClientSideValidations.forms[$form.attr('id')],
Method import
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def import
@csv.each do |row|
row = transform_row(row)
if @params[:associate_vendor_account]
- 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 serialized
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def serialized(*args)
obj = args[0]
is_collection = obj.respond_to?(:each)
if args[1].is_a?(Hash)
Method add_params_to_query
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def self.add_params_to_query(query, params, args = {})
if !params[:q].blank?
query = query.full_search(params[:q])
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 add_params_to_query
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def self.add_params_to_query(query, params, args = {})
if params[:q] && !params[:q].blank?
query = query.full_search(params[:q])
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
Function inclusion
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
inclusion: function(element, options) {
var lower, message, option, upper, _ref;
message = this.presence(element, options);
if (message) {
if (options.allow_blank === true) {