CartoDB/cartodb20

View on GitHub
lib/assets/javascripts/cartodb/models/map.js

Summary

Maintainability
F
6 days
Test Coverage

File map.js has 650 lines of code (exceeds 250 allowed). Consider refactoring.
Open


/*
 * extend infowindow to serialize only the data we need
 */
_.extend(cdb.geo.ui.InfowindowModel.prototype, {
Severity: Major
Found in lib/assets/javascripts/cartodb/models/map.js - About 1 day to fix

    Map has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

    cdb.admin.Map = cdb.geo.Map.extend({
    
      urlRoot: '/api/v1/maps',
    
      initialize: function() {
    Severity: Minor
    Found in lib/assets/javascripts/cartodb/models/map.js - About 3 hrs to fix

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

        setBaseLayer: function(baseLayer) {
          this.trigger('savingLayers');
      
          // Check if the selected base layer is already selected
          if (this.isBaseLayerAdded(baseLayer)) {
      Severity: Minor
      Found in lib/assets/javascripts/cartodb/models/map.js - About 2 hrs 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 setBaseLayer has 44 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        setBaseLayer: function(baseLayer) {
          this.trigger('savingLayers');
      
          // Check if the selected base layer is already selected
          if (this.isBaseLayerAdded(baseLayer)) {
      Severity: Minor
      Found in lib/assets/javascripts/cartodb/models/map.js - About 1 hr to fix

        Function addCartodbLayerFromTable has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          addCartodbLayerFromTable: function(tableName, userName, opts) {
            opts = opts || {};
            /*var newLayer = cdb.admin.CartoDBLayer.createDefaultLayerForTable(tableName, userName);
            this.layers.add(newLayer);
            newLayer.save(null, opts);
        Severity: Minor
        Found in lib/assets/javascripts/cartodb/models/map.js - About 1 hr to fix

          Function getLayerDefIndex has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            getLayerDefIndex: function(layer) {
              var cartodbLayers = this.getLayersByType('CartoDB');
              if(!cartodbLayers.length) return -1;
              for(var i = 0, c = 0; i < cartodbLayers.length; ++i) {
                if(cartodbLayers[i].get('visible')) {
          Severity: Minor
          Found in lib/assets/javascripts/cartodb/models/map.js - About 35 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

            validateTemplateURL: function(callbacks) {
              var subdomains = ['a', 'b', 'c'];
              var image = new Image();
              image.onload = callbacks.success;
              image.onerror = callbacks.error;
          Severity: Major
          Found in lib/assets/javascripts/cartodb/models/map.js and 1 other location - About 5 hrs to fix
          lib/assets/javascripts/builder/data/custom-baselayer-model.js on lines 53..64

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

          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

            parse: function(data) {
          
              var self = this;
              var c = {};
          
          
          Severity: Major
          Found in lib/assets/javascripts/cartodb/models/map.js and 1 other location - About 3 hrs to fix
          lib/assets/javascripts/cartodb/models/map.js on lines 223..236

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

          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

            parse: function(data) {
              var self = this;
              var c = {};
          
              _.extend(c, data.options, {
          Severity: Major
          Found in lib/assets/javascripts/cartodb/models/map.js and 1 other location - About 3 hrs to fix
          lib/assets/javascripts/cartodb/models/map.js on lines 140..154

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

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

            toJSON: function() {
              var c = _.clone(this.attributes);
          
              var d = {
                kind:  'background',
          Severity: Major
          Found in lib/assets/javascripts/cartodb/models/map.js and 3 other locations - About 2 hrs to fix
          lib/assets/javascripts/cartodb/models/map.js on lines 99..112
          lib/assets/javascripts/cartodb/models/map.js on lines 156..169
          lib/assets/javascripts/cartodb/models/map.js on lines 238..251

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

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

            toJSON: function() {
              var c = _.clone(this.attributes);
          
              var d = {
                kind:  'wms',
          Severity: Major
          Found in lib/assets/javascripts/cartodb/models/map.js and 3 other locations - About 2 hrs to fix
          lib/assets/javascripts/cartodb/models/map.js on lines 99..112
          lib/assets/javascripts/cartodb/models/map.js on lines 189..202
          lib/assets/javascripts/cartodb/models/map.js on lines 238..251

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

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

            toJSON: function() {
              var c = _.clone(this.attributes);
          
              var d = {
                kind:  'tiled',
          Severity: Major
          Found in lib/assets/javascripts/cartodb/models/map.js and 3 other locations - About 2 hrs to fix
          lib/assets/javascripts/cartodb/models/map.js on lines 99..112
          lib/assets/javascripts/cartodb/models/map.js on lines 156..169
          lib/assets/javascripts/cartodb/models/map.js on lines 189..202

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

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

            toJSON: function() {
              var c = _.clone(this.attributes);
          
              var d = {
                kind:  'gmapsbase',
          Severity: Major
          Found in lib/assets/javascripts/cartodb/models/map.js and 3 other locations - About 2 hrs to fix
          lib/assets/javascripts/cartodb/models/map.js on lines 156..169
          lib/assets/javascripts/cartodb/models/map.js on lines 189..202
          lib/assets/javascripts/cartodb/models/map.js on lines 238..251

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

          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

            parse: function(data) {
              var c = {};
              _.extend(c, data.options, {
                id: data.id,
                type: 'Plain',
          Severity: Major
          Found in lib/assets/javascripts/cartodb/models/map.js and 1 other location - About 1 hr to fix
          lib/assets/javascripts/cartodb/models/map.js on lines 88..97

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

          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

            parse: function(data) {
              var c = {};
              _.extend(c, data.options, {
                id: data.id,
                type: 'GMapsBase',
          Severity: Major
          Found in lib/assets/javascripts/cartodb/models/map.js and 1 other location - About 1 hr to fix
          lib/assets/javascripts/cartodb/models/map.js on lines 178..187

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

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

            url: function(method) {
              var version = cdb.config.urlVersion('layer', method);
              return '/api/' + version + '/maps/' +  this.map.id + '/layers';
            },
          Severity: Major
          Found in lib/assets/javascripts/cartodb/models/map.js and 4 other locations - About 1 hr to fix
          lib/assets/javascripts/cartodb/models/assets.js on lines 25..28
          lib/assets/javascripts/cartodb/models/grantables.js on lines 8..11
          lib/assets/javascripts/cartodb/models/organization_groups.js on lines 8..11
          lib/assets/javascripts/cartodb/models/user.js on lines 7..10

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

          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

            _generateClassName: function(urlTemplate) {
              if (urlTemplate) {
                return urlTemplate.replace(/\s+/g, '').replace(/[^a-zA-Z_0-9 ]/g, "").toLowerCase();
              } else return "";
            },
          Severity: Minor
          Found in lib/assets/javascripts/cartodb/models/map.js and 1 other location - About 35 mins to fix
          lib/assets/javascripts/builder/data/custom-baselayer-model.js on lines 12..16

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

          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

              for(var i = 0; i < fields.length; ++i) {
                columns.push(fields[i].name);
              }
          Severity: Minor
          Found in lib/assets/javascripts/cartodb/models/map.js and 1 other location - About 35 mins to fix
          lib/assets/javascripts/cartodb/models/carto.js on lines 601..603

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

              url = url.replace(/\{S\}/g, "{s}")
                .replace(/\{X\}/g, "{x}")
                .replace(/\{Y\}/g, "{y}")
                .replace(/\{Z\}/g, "{z}");
          Severity: Minor
          Found in lib/assets/javascripts/cartodb/models/map.js and 2 other locations - About 30 mins to fix
          lib/assets/javascripts/builder/components/modals/add-basemap/wms/wms-layer-model.js on lines 143..146
          lib/assets/javascripts/builder/components/modals/add-basemap/xyz/xyz-view.js on lines 135..138

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

          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

              if (newBaseLayerHasLabels) {
                if (this._hasLabelsLayer()) {
                  this._updateLabelsLayer(newBaseLayer, options);
                } else {
                  this._addLabelsLayer(newBaseLayer, options);
          Severity: Minor
          Found in lib/assets/javascripts/cartodb/models/map.js and 1 other location - About 30 mins to fix
          lib/assets/javascripts/deep-insights/widgets/histogram/content-view.js on lines 420..426

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

          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