Showing 3,486 of 3,486 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
def to_s
begin user_name = User.find(user_id).to_s rescue user_name = '-?-' end
begin role_name = Role.find(role_id).to_s rescue role_name = '-?-' end
begin jur_name = Jurisdiction.find(jurisdiction_id).to_s rescue jur_name = '-?-' end
user_name + ' for ' + role_name + ' in ' + jur_name
- 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 41.
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
Avoid deeply nested control flow statements. Open
if(folderSelections[0] && folderSelections[0].get('type').match(/share|organization/)){ // we want to figure out what sharing permissions we have, eventually, but for now, roll with it
show.push('copy_action_container', 'file_detail_container');
if(folderSelections[0].get('is_owner')){
show.push('move_action_container');
}
Avoid deeply nested control flow statements. Open
for ( var handle in events[type] )
// Handle the removal of namespaced events
if ( namespace.test(events[type][handle].type) )
delete events[type][handle];
Avoid deeply nested control flow statements. Open
for ( var i = 0; (item = curLoop[i]) != null; i++ ) {
if ( item ) {
found = filter( item, match, i, curLoop );
var pass = not ^ !!found;
Function run_search
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
run_search: function(val){
if (!Ext.isEmpty(val) && val.length >= 2){
var own = this.getComponent('search_form').getComponent('my_files').checked;
var shared = this.getComponent('search_form').getComponent('shared_files').checked;
if(own || shared){ // We only want to do this if the file is either owned or shared.
- 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 ( !inplace ) {
curLoop = result;
}
Avoid deeply nested control flow statements. Open
if(sel.get('is_owner')){
show.push('folder_action_container', 'move_action_container');
this._add_folder_button.show();
}
Avoid deeply nested control flow statements. Open
if ( results[i] === results[i-1] ) {
results.splice(i--, 1);
}
Function CLASS
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
CLASS: function(match, curLoop, inplace, result, not, isXML){
Avoid deeply nested control flow statements. Open
if ( typeof cur !== "string" ) {
if ( elem === cur ) {
match = true;
break;
}
Function renderer
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
renderer: function(value, metaData, record, rowIndex, colIndex, store) {
Function dirCheck
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
Avoid deeply nested control flow statements. Open
if ( option.selected ) {
// Get the specifc value for the option
value = jQuery(option).val();
// We don't need an array for one selects
Avoid deeply nested control flow statements. Open
if ( !match ) {
anyFound = found = true;
} else if ( match === true ) {
continue;
}
Avoid deeply nested control flow statements. Open
if ( display === "none" )
display = "block";
Function ATTR
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
ATTR: function(match, curLoop, inplace, result, not, isXML){
Function dirNodeCheck
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
Avoid deeply nested control flow statements. Open
if ( !anyFound ) {
return [];
}
Avoid deeply nested control flow statements. Open
if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call(elem, namespaces) === false ) {
if (elem.removeEventListener)
elem.removeEventListener(type, jQuery.data(elem, "handle"), false);
else if (elem.detachEvent)
elem.detachEvent("on" + type, jQuery.data(elem, "handle"));
Function applyModelSelections
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
applyModelSelections : function(){
var selected_models = this.modelList.getSelectedRecords();
if ( selected_models.length > 0 ){
var models = [];
for (var i = 0; i < selected_models.length; i++){
- 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"