CartoDB/cartodb20

View on GitHub
lib/assets/javascripts/builder/data/layer-definitions-collection.js

Summary

Maintainability
D
2 days
Test Coverage

exports has 34 functions (exceeds 20 allowed). Consider refactoring.
Open

module.exports = Backbone.Collection.extend({

  initialize: function (models, opts) {
    checkAndBuildOpts(opts, REQUIRED_OPTS, this);
  },
Severity: Minor
Found in lib/assets/javascripts/builder/data/layer-definitions-collection.js - About 4 hrs to fix

    File layer-definitions-collection.js has 328 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    var $ = require('jquery');
    var _ = require('underscore');
    var Backbone = require('backbone');
    var LayerDefinitionModel = require('./layer-definition-model');
    var layerLetters = require('./layer-letters');
    Severity: Minor
    Found in lib/assets/javascripts/builder/data/layer-definitions-collection.js - About 3 hrs to fix

      Function setBaseLayer has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        setBaseLayer: function (newBaseLayerAttrs) {
          this.trigger('changingBaseLayer');
      
          newBaseLayerAttrs = _.clone(newBaseLayerAttrs);
          if (this.isBaseLayerAdded(newBaseLayerAttrs)) {
      Severity: Minor
      Found in lib/assets/javascripts/builder/data/layer-definitions-collection.js - About 1 hr to fix

        Function setBaseLayer has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

          setBaseLayer: function (newBaseLayerAttrs) {
            this.trigger('changingBaseLayer');
        
            newBaseLayerAttrs = _.clone(newBaseLayerAttrs);
            if (this.isBaseLayerAdded(newBaseLayerAttrs)) {
        Severity: Minor
        Found in lib/assets/javascripts/builder/data/layer-definitions-collection.js - About 1 hr to fix

        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 model has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          model: function (d, opts) {
            var self = opts.collection;
        
            // Add data required for new editor if not set (e.g. a vis created on old editor doesn't contain letter and source)
            var o = _.clone(d.options) || {};
        Severity: Minor
        Found in lib/assets/javascripts/builder/data/layer-definitions-collection.js - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

                if (o.table_name && (!o.source || o.source === sourceId)) {
                  var tableName = TableNameUtils.getUnqualifiedName(o.table_name);
                  var userName = o.user_name || TableNameUtils.getUsername(o.table_name);
          
                  var qualifyTableName = (userName && self._configModel.get('user_name') !== userName) || self._userModel.isInsideOrg();
          Severity: Critical
          Found in lib/assets/javascripts/builder/data/layer-definitions-collection.js - About 1 hr to fix

            Function model has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              model: function (d, opts) {
                var self = opts.collection;
            
                // Add data required for new editor if not set (e.g. a vis created on old editor doesn't contain letter and source)
                var o = _.clone(d.options) || {};
            Severity: Minor
            Found in lib/assets/javascripts/builder/data/layer-definitions-collection.js - About 1 hr to fix

            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 loadAllQueryGeometryModels has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              loadAllQueryGeometryModels: function (callback) {
                var promises = this.filter(function (layerDefModel) {
                  return layerDefModel.isDataLayer();
                }).map(function (layerDefModel) {
                  var queryGeometryModel = layerDefModel.getAnalysisDefinitionNodeModel().queryGeometryModel;
            Severity: Minor
            Found in lib/assets/javascripts/builder/data/layer-definitions-collection.js - About 1 hr to fix

              Function loadAllQueryGeometryModels has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                loadAllQueryGeometryModels: function (callback) {
                  var promises = this.filter(function (layerDefModel) {
                    return layerDefModel.isDataLayer();
                  }).map(function (layerDefModel) {
                    var queryGeometryModel = layerDefModel.getAnalysisDefinitionNodeModel().queryGeometryModel;
              Severity: Minor
              Found in lib/assets/javascripts/builder/data/layer-definitions-collection.js - About 45 mins to fix

              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

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

                  var hasLabels = layerOnTop &&
                    !layerTypesAndKinds.isCartoDBType(layerOnTop.get('type')) &&
                    !layerTypesAndKinds.isTorqueType(layerOnTop.get('type'));
              lib/assets/javascripts/builder/data/user-actions.js on lines 313..315

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

              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 7 locations. Consider refactoring.
              Open

                url: function () {
                  var baseUrl = this._configModel.get('base_url');
                  return baseUrl + '/api/v1/maps/' + this._mapId + '/layers';
                },
              lib/assets/javascripts/builder/data/analysis-definitions-collection.js on lines 32..35
              lib/assets/javascripts/builder/data/vis-definition-model.js on lines 49..52
              lib/assets/javascripts/builder/data/vis-definition-model.js on lines 62..65
              lib/assets/javascripts/builder/data/vis-definition-model.js on lines 73..76
              lib/assets/javascripts/builder/data/widget-definitions-collection.js on lines 75..78
              lib/assets/javascripts/dashboard/data/visualization-model.js on lines 265..268

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

              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

                isThereAnyCartoDBLayer: function () {
                  return this.any(function (model) {
                    return layerTypesAndKinds.isCartoDBType(model.get('type'));
                  });
                },
              lib/assets/javascripts/builder/data/layer-definitions-collection.js on lines 208..212

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

              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

                isThereAnyTorqueLayer: function () {
                  return this.any(function (model) {
                    return layerTypesAndKinds.isTorqueType(model.get('type'));
                  });
                },
              lib/assets/javascripts/builder/data/layer-definitions-collection.js on lines 214..218

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

              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