Vizzuality/gfw-climate

View on GitHub
app/assets/javascripts/services/CountryService.js

Summary

Maintainability
F
3 days
Test Coverage

File CountryService.js has 312 lines of code (exceeds 250 allowed). Consider refactoring.
Open

define(
  ['Class', 'uri', 'underscore', 'bluebird', 'map/services/DataService'],
  function(Class, UriTemplate, _, Promise, ds) {
    'use strict';

Severity: Minor
Found in app/assets/javascripts/services/CountryService.js - About 3 hrs to fix

    Function getCountry has 66 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          getCountry: function(params, statsOption) {
            var stats = statsOption || false;
            var datasetId =
              GET_REQUEST_COUNTRY_ID + '_' + params.iso + '_' + stats
                ? 'withStats'
    Severity: Major
    Found in app/assets/javascripts/services/CountryService.js - About 2 hrs to fix

      Function getCountries has 53 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            getCountries: function(options) {
              var filters = options || {
                geo: false
              };
              return new Promise(
      Severity: Major
      Found in app/assets/javascripts/services/CountryService.js - About 2 hrs to fix

        Function getClimateConfig has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              getClimateConfig: function(params) {
                return new Promise(
                  function(resolve, reject) {
                    var status = _.extend({}, CONFIG, params);
                    var url = new UriTemplate(APIURLS.getClimateConfig).fillFromObject(
        Severity: Minor
        Found in app/assets/javascripts/services/CountryService.js - About 1 hr to fix

          Function getCountryStats has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                getCountryStats: function(params) {
                  return new Promise(
                    function(resolve, reject) {
                      this.getClimateConfig()
                        .then(
          Severity: Minor
          Found in app/assets/javascripts/services/CountryService.js - About 1 hr to fix

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

                  showRegion: function(params) {
                    var datasetId =
                      SHOW_REQUEST_REGION_ID + '_' + params.iso + '_' + params.region;
                    return new Promise(
                      function(resolve, reject) {
            Severity: Minor
            Found in app/assets/javascripts/services/CountryService.js - About 1 hr to fix

              Function decoder has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                        decoder: function(data, status, xhr, success, error) {
              Severity: Minor
              Found in app/assets/javascripts/services/CountryService.js - About 35 mins to fix

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

                        return new Promise(
                          function(resolve, reject) {
                            var status = _.extend({}, CONFIG, params);
                            var url = new UriTemplate(APIURLS.getCountry).fillFromObject(
                              status
                Severity: Major
                Found in app/assets/javascripts/services/CountryService.js and 1 other location - About 6 hrs to fix
                app/assets/javascripts/services/CountryService.js on lines 256..281

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

                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

                        return new Promise(
                          function(resolve, reject) {
                            var status = _.extend({}, CONFIG, params);
                            var url = new UriTemplate(APIURLS.getRegionsList).fillFromObject(
                              status
                Severity: Major
                Found in app/assets/javascripts/services/CountryService.js and 1 other location - About 6 hrs to fix
                app/assets/javascripts/services/CountryService.js on lines 227..252

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

                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

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

                          decoder: function(data, status, xhr, success, error) {
                            if (status === 'success') {
                              success(data, xhr);
                            } else if (status === 'fail' || status === 'error') {
                              error(xhr.statusText);
                Severity: Major
                Found in app/assets/javascripts/services/CountryService.js and 1 other location - About 3 hrs to fix
                app/assets/javascripts/services/ContinentService.js on lines 81..91

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

                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

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

                      abortRequest: function(request) {
                        if (this.currentRequest && this.currentRequest[request]) {
                          this.currentRequest[request].abort();
                          this.currentRequest[request] = null;
                        }
                Severity: Major
                Found in app/assets/javascripts/services/CountryService.js and 1 other location - About 1 hr to fix
                app/assets/javascripts/services/ContinentService.js on lines 98..103

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

                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

                    var APIURLS = {
                      getClimateConfig: '/query?sql=SELECT iso FROM {countriesConfigDataset}',
                      getCountriesList:
                        '/query?sql=SELECT name_engli as name, iso FROM {countriesDataset} WHERE iso IN({climateCountries}) ORDER BY name ASC',
                      getCountriesListGeo:
                Severity: Minor
                Found in app/assets/javascripts/services/CountryService.js and 1 other location - About 40 mins to fix
                app/assets/javascripts/map/views/maptypes/basemapStyles.js on lines 7..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 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

                There are no issues that match your filters.

                Category
                Status