File backbone.js
has 1154 lines of code (exceeds 250 allowed). Consider refactoring. Open
// Backbone.js 1.3.3
// (c) 2010-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
- Create a ticketCreate a ticket
Function set
has 88 lines of code (exceeds 25 allowed). Consider refactoring. Open
set: function(models, options) {
if (models == null) return;
options = _.extend({}, setOptions, options);
if (options.parse && !this._isModel(models)) {
- Create a ticketCreate a ticket
Function set
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
set: function(key, val, options) {
if (key == null) return this;
// Handle both `"key", value` and `{key: value}` -style arguments.
var attrs;
- Create a ticketCreate a ticket
Function start
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
start: function(options) {
if (History.started) throw new Error('Backbone.history has already been started');
History.started = true;
// Figure out the initial configuration. Do we need an iframe?
- Create a ticketCreate a ticket
Function offApi
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
var offApi = function(events, name, callback, options) {
if (!events) return;
var i = 0, listening;
var context = options.context, listeners = options.listeners;
- Create a ticketCreate a ticket
Function sync
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
Backbone.sync = function(method, model, options) {
var type = methodMap[method];
// Default options, unless specified.
_.defaults(options || (options = {}), {
- Create a ticketCreate a ticket
Function save
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
save: function(key, val, options) {
// Handle both `"key", value` and `{key: value}` -style arguments.
var attrs;
if (key == null || typeof key === 'object') {
attrs = key;
- Create a ticketCreate a ticket
Function navigate
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
navigate: function(fragment, options) {
if (!History.started) return false;
if (!options || options === true) options = {trigger: !!options};
// Normalize the fragment.
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) {
params.contentType = 'application/json';
params.data = JSON.stringify(options.attrs || model.toJSON(options));
}
- Create a ticketCreate a ticket
Function internalOn
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
var internalOn = function(obj, name, callback, context, listening) {
- Create a ticketCreate a ticket
Function eventsApi
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
var eventsApi = function(iteratee, events, name, callback, opts) {
- Create a ticketCreate a ticket
Avoid too many return
statements within this function. Open
default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args); return;
- Create a ticketCreate a ticket
Similar blocks of code found in 2 locations. Consider refactoring. Open
var root = (typeof self == 'object' && self.self === self && self) ||
(typeof global == 'object' && global.global === global && global);
- 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 49.
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