File fileinput.js
has 2632 lines of code (exceeds 250 allowed). Consider refactoring. Open
/*!
* @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 4.2.8
*
* File input styled for Bootstrap 3.0 that utilizes HTML5 File Input's advanced
- Create a ticketCreate a ticket
Function readFiles
has 133 lines of code (exceeds 25 allowed). Consider refactoring. Open
readFiles: function (files) {
this.reader = new FileReader();
var self = this, $el = self.$element, $preview = self.$preview, reader = self.reader,
$container = self.$previewContainer, $status = self.$previewStatus, msgLoading = self.msgLoading,
msgProgress = self.msgProgress, previewInitId = self.previewInitId, numFiles = files.length,
- Create a ticketCreate a ticket
Function uploadSingle
has 125 lines of code (exceeds 25 allowed). Consider refactoring. Open
uploadSingle: function (i, files, allFiles) {
var self = this, total = self.getFileStack().length, formdata = new FormData(), outData,
previewId = self.previewInitId + "-" + i, $thumb, chkComplete, $btnUpload, $btnDelete,
hasPostData = self.filestack.length > 0 || !$.isEmptyObject(self.uploadExtraData),
fnBefore, fnSuccess, fnComplete, fnError, updateUploadLog, params = {id: previewId, index: i};
- Create a ticketCreate a ticket
Function uploadBatch
has 109 lines of code (exceeds 25 allowed). Consider refactoring. Open
uploadBatch: function () {
var self = this, files = self.filestack, total = files.length, params = {},
hasPostData = self.filestack.length > 0 || !$.isEmptyObject(self.uploadExtraData),
setAllUploaded, fnBefore, fnSuccess, fnComplete, fnError;
self.formdata = new FormData();
- Create a ticketCreate a ticket
Function change
has 85 lines of code (exceeds 25 allowed). Consider refactoring. Open
change: function (e) {
var self = this, $el = self.$element;
if (!self.isUploadable && isEmpty($el.val()) && self.fileInputCleared) { // IE 11 fix
self.fileInputCleared = false;
return;
- Create a ticketCreate a ticket
Function initPreviewDeletes
has 81 lines of code (exceeds 25 allowed). Consider refactoring. Open
initPreviewDeletes: function () {
var self = this, deleteExtraData = self.deleteExtraData || {},
resetProgress = function () {
var hasFiles = self.isUploadable ? previewCache.count(self.id) : self.$element.get(0).files.length;
if (self.$preview.find('.kv-file-remove').length === 0 && !hasFiles) {
- Create a ticketCreate a ticket
Function init
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
init: function (options) {
var self = this, $el = self.$element, t;
$.each(options, function (key, value) {
switch (key) {
case 'minFileCount':
- Create a ticketCreate a ticket
Function initFileActions
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
initFileActions: function () {
var self = this;
if (!self.showPreview) {
return;
}
- Create a ticketCreate a ticket
Function set
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
set: function (id, content, config, tags, append) {
var data = $.extend(true, {}, previewCache.data[id]), i, chk;
if (!content || !content.length) {
return;
}
- Create a ticketCreate a ticket
Function upload
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
upload: function () {
var self = this, totLen = self.getFileStack().length, params = {},
i, outData, len, hasExtraData = !$.isEmptyObject(self.getExtraData());
if (self.minFileCount > 0 && self.getFileCount(totLen) < self.minFileCount) {
self.noFilesError(params);
- Create a ticketCreate a ticket
Function renderButton
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
renderButton: function (type) {
var self = this, tmplt = self.getLayoutTemplate('btnDefault'), css = self[type + 'Class'],
title = self[type + 'Title'], icon = self[type + 'Icon'], label = self[type + 'Label'],
status = self.isDisabled ? ' disabled' : '', btnType = 'button';
switch (type) {
- Create a ticketCreate a ticket
Function uploadExtraOnly
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
uploadExtraOnly: function () {
var self = this, params = {}, fnBefore, fnSuccess, fnComplete, fnError;
self.formdata = new FormData();
if (self.abort(params)) {
return;
- Create a ticketCreate a ticket
Function previewFile
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
previewFile: function (i, file, theFile, previewId, data) {
if (!this.showPreview) {
return;
}
var self = this, cat = self.parseFileType(file), fname = file ? file.name : '', caption = self.slug(fname),
- Create a ticketCreate a ticket
Function clear
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
clear: function () {
var self = this, cap;
self.$btnUpload.removeAttr('disabled');
self.getThumbs().find('video,audio,img').each(function () {
self.cleanMemory($(this));
- Create a ticketCreate a ticket
Function listen
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
listen: function () {
var self = this, $el = self.$element, $cap = self.$captionContainer, $btnFile = self.$btnFile,
$form = $el.closest('form'), $cont = self.$container;
handler($el, 'change', $.proxy(self.change, self));
handler($btnFile, 'click', function () {
- Create a ticketCreate a ticket
Function initUploadSuccess
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
initUploadSuccess: function (out, $thumb, allFiles) {
var self = this, append, data, index, $newThumb, content, config, tags, i;
if (!self.showPreview || typeof out !== 'object' || $.isEmptyObject(out)) {
return;
}
- Create a ticketCreate a ticket
Function getResizedImage
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
getResizedImage: function (image, type, pid, ind) {
var self = this, width = image.naturalWidth, height = image.naturalHeight, ratio = 1,
maxWidth = self.maxImageWidth || width, maxHeight = self.maxImageHeight || height,
isValidImage = (width && height), chkWidth, chkHeight,
canvas = self.imageCanvas, context = self.imageCanvasContext;
- Create a ticketCreate a ticket
Function initDragDrop
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
initDragDrop: function () {
var self = this, $zone = self.$container.find('.file-drop-zone'),
allEvents = 'dragenter.fileinput dragover.fileinput drop.fileinput';
handler($zone, 'dragenter.fileinput dragover.fileinput', function (e) {
var hasFiles = $.inArray('Files', e.originalEvent.dataTransfer.types) > -1;
- Create a ticketCreate a ticket
Function raise
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
raise: function (event, params) {
var self = this, e = $.Event(event);
if (params !== undefined) {
self.$element.trigger(e, params);
} else {
- Create a ticketCreate a ticket
Function fileinput
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
$.fn.fileinput = function (option) {
if (!hasFileAPISupport() && !isIE(9)) {
return;
}
var args = Array.apply(null, arguments), retvals = [];
- Create a ticketCreate a ticket
Function previewDefault
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
previewDefault: function (file, previewId, isDisabled) {
if (!this.showPreview) {
return;
}
var self = this, frameClass = '', fname = file ? file.name : '',
- Create a ticketCreate a ticket
Function renderFileActions
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
renderFileActions: function (showUpload, showDelete, disabled, url, key) {
if (!showUpload && !showDelete) {
return '';
}
var self = this,
- Create a ticketCreate a ticket
Function success
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
success: function (data, textStatus, jqXHR) {
var n, cap;
if (isEmpty(data) || isEmpty(data.error)) {
previewCache.unset(self.id, index);
n = previewCache.count(self.id);
- Create a ticketCreate a ticket
Function checkDimensions
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
checkDimensions: function (i, chk, $img, $thumb, fname, type, params) {
- Create a ticketCreate a ticket
Function ajaxSubmit
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
ajaxSubmit: function (fnBefore, fnSuccess, fnComplete, fnError, previewId, index) {
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (out.initialPreview !== undefined && out.initialPreview.length > 0) {
self.hasInitData = true;
content = out.initialPreview || [];
config = out.initialPreviewConfig || [];
tags = out.initialPreviewThumbTags || [];
- Create a ticketCreate a ticket
Function actions
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
actions: function (showUpload, showDelete, disabled, url, key) {
- Create a ticketCreate a ticket
Function set
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
set: function (id, content, config, tags, append) {
- Create a ticketCreate a ticket
Function add
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
add: function (id, content, config, tags, append) {
- Create a ticketCreate a ticket
Function renderFileActions
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
renderFileActions: function (showUpload, showDelete, disabled, url, key) {
- Create a ticketCreate a ticket
Function previewFile
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
previewFile: function (i, file, theFile, previewId, data) {
- Create a ticketCreate a ticket
Similar blocks of code found in 2 locations. Consider refactoring. Open
getLayoutTemplate: function (t) {
var self = this,
template = isSet(t, self.layoutTemplates) ? self.layoutTemplates[t] : defaultLayoutTemplates[t];
if (isEmpty(self.customLayoutTags)) {
return template;
- Read upRead up
- Create a ticketCreate a ticket
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 80.
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
getPreviewTemplate: function (t) {
var self = this,
template = isSet(t, self.previewTemplates) ? self.previewTemplates[t] : defaultPreviewTemplates[t];
if (isEmpty(self.customPreviewTags)) {
return template;
- Read upRead up
- Create a ticketCreate a ticket
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 80.
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
var p1 = $.extend(self.getOutData({}, {}, files), {id: previewId, index: index}),
p2 = {id: previewId, index: index, file: file, files: files};
- Read upRead up
- Create a ticketCreate a ticket
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 65.
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
var p1 = $.extend(self.getOutData({}, {}, files), {id: previewId, index: index}),
p2 = {id: previewId, index: index, file: file, files: files};
- Read upRead up
- Create a ticketCreate a ticket
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 65.
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
getFileStack: function (skipNull) {
var self = this;
return self.filestack.filter(function (n) {
return (skipNull ? n !== undefined : n !== undefined && n !== null);
});
- Read upRead up
- Create a ticketCreate a ticket
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 64.
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
getFileNames: function (skipNull) {
var self = this;
return self.filenames.filter(function (n) {
return (skipNull ? n !== undefined : n !== undefined && n !== null);
});
- Read upRead up
- Create a ticketCreate a ticket
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 64.
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 (fileCount === 0) {
msg = self.msgInvalidFileType.replace('{name}', caption).replace('{types}', strTypes);
self.isError = throwError(msg, file, previewId, i);
return;
}
- Read upRead up
- Create a ticketCreate a ticket
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 59.
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 (fileCount === 0) {
msg = self.msgInvalidFileExtension.replace('{name}', caption).replace('{extensions}',
strExt);
self.isError = throwError(msg, file, previewId, i);
return;
- Read upRead up
- Create a ticketCreate a ticket
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 59.
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 3 locations. Consider refactoring. Open
for (i = 0; i < config.length; i++) {
if (config[i]) {
data.config.push(config[i]);
}
}
- Read upRead up
- Create a ticketCreate a ticket
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 55.
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 3 locations. Consider refactoring. Open
for (i = 0; i < content.length; i++) {
if (content[i]) {
data.content.push(content[i]);
}
}
- Read upRead up
- Create a ticketCreate a ticket
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 55.
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 3 locations. Consider refactoring. Open
for (i = 0; i < tags.length; i++) {
if (tags[i]) {
data.tags.push(tags[i]);
}
}
- Read upRead up
- Create a ticketCreate a ticket
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 55.
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