agilejzl/blog-eye

View on GitHub
app/assets/javascripts/shared/backbone.js

Summary

Maintainability
F
4 days
Test Coverage

File backbone.js has 956 lines of code (exceeds 250 allowed). Consider refactoring.
Open

//     Backbone.js 1.1.2

//     (c) 2010-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
//     Backbone may be freely distributed under the MIT license.
//     For all details and documentation:
Severity: Major
Found in app/assets/javascripts/shared/backbone.js - About 2 days to fix

Function set has 67 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    set: function(models, options) {
      options = _.defaults({}, options, setOptions);
      if (options.parse) models = this.parse(models, options);
      var singular = !_.isArray(models);
      models = singular ? (models ? [models] : []) : _.clone(models);
Severity: Major
Found in app/assets/javascripts/shared/backbone.js - About 2 hrs to fix

Function set has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    set: function(key, val, options) {
      var attr, attrs, unset, changes, silent, changing, prev, current;
      if (key == null) return this;

      // Handle both `"key", value` and `{key: value}` -style arguments.
Severity: Minor
Found in app/assets/javascripts/shared/backbone.js - About 1 hr to fix

Function sync has 37 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 = {}), {
Severity: Minor
Found in app/assets/javascripts/shared/backbone.js - About 1 hr to fix

Function start has 36 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?
Severity: Minor
Found in app/assets/javascripts/shared/backbone.js - About 1 hr to fix

Function save has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    save: function(key, val, options) {
      var attrs, method, xhr, attributes = this.attributes;

      // Handle both `"key", value` and `{key: value}` -style arguments.
      if (key == null || typeof key === 'object') {
Severity: Minor
Found in app/assets/javascripts/shared/backbone.js - About 1 hr to fix

Avoid deeply nested control flow statements.
Open

              if ((callback && callback !== ev.callback && callback !== ev.callback._callback) ||
                  (context && context !== ev.context)) {
                retain.push(ev);
              }
Severity: Major
Found in app/assets/javascripts/shared/backbone.js - About 45 mins to fix

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));
    }
Severity: Major
Found in app/assets/javascripts/shared/backbone.js - About 40 mins to fix

Avoid too many return statements within this function.
Open

      default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args); return;
Severity: Major
Found in app/assets/javascripts/shared/backbone.js - About 30 mins to fix

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  _.each(methods, function(method) {
    Collection.prototype[method] = function() {
      var args = slice.call(arguments);
      args.unshift(this.models);
      return _[method].apply(_, args);
Severity: Major
Found in app/assets/javascripts/shared/backbone.js and 1 other location - About 2 hrs to fix
app/assets/javascripts/shared/backbone.js on lines 580..586

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 83.

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

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  _.each(modelMethods, function(method) {
    Model.prototype[method] = function() {
      var args = slice.call(arguments);
      args.unshift(this.attributes);
      return _[method].apply(_, args);
Severity: Major
Found in app/assets/javascripts/shared/backbone.js and 1 other location - About 2 hrs to fix
app/assets/javascripts/shared/backbone.js on lines 962..968

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 83.

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

Further Reading

There are no issues that match your filters.

Category
Status