publiclab/mapknitter

View on GitHub

Showing 127 of 127 total issues

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

  def batch_publish_maps
    published_maps = 0
    unbanned_authors = 0
    params[:ids].split(',').uniq.each do |id|
      map = Map.find(id)
Severity: Major
Found in app/controllers/spam_controller.rb and 1 other location - About 1 hr to fix
app/controllers/spam_controller.rb on lines 51..62

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

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

  def batch_spam_maps
    spammed_maps = 0
    banned_authors = 0
    params[:ids].split(',').uniq.each do |id|
      map = Map.find(id)
Severity: Major
Found in app/controllers/spam_controller.rb and 1 other location - About 1 hr to fix
app/controllers/spam_controller.rb on lines 77..88

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

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

Method create has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def create
    @openid_url_base = "https://publiclab.org/people/"
    @openid_url_suffix = "/identity"
    back_to = params[:back_to]
    # we pass a temp username; on line 75 it'll be overwritten by the real one in PublicLab.org's response:
Severity: Minor
Found in app/controllers/sessions_controller.rb - 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 synchronizeData has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  synchronizeData: function(warpables) {
    var layers = [];
    map.eachLayer(function(l) {layers.push(l)});
    layers = layers.filter(image => !!image._url);
    warpables.forEach(function(warpable) {
Severity: Minor
Found in app/assets/javascripts/mapknitter/Map.js - About 1 hr to fix

    Function initialize has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      initialize: function(options) {
        MapKnitter.Resources.prototype.initialize.call(this, options);
    
        var map = options.map,
        drawOptions = {};
    Severity: Minor
    Found in app/assets/javascripts/mapknitter/Annotations.js - About 1 hr to fix

      Function _initEvents has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _initEvents: function() {
          var map = this._map;
      
          map.on('draw:created', function(event) {
            var layer = event.layer;
      Severity: Minor
      Found in app/assets/javascripts/mapknitter/Annotations.js - About 1 hr to fix

        Function geocodeImageFromId has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          geocodeImageFromId: function (dom_id, id, url) {
            mapknitter.geocodeImage(
              $(dom_id)[0],
              function (lat, lng, id, angle, altitude) {
                /* Display button to place this image with GPS tags. */
        Severity: Minor
        Found in app/assets/javascripts/mapknitter/Map.js - About 1 hr to fix

          Method errors_for has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

            def errors_for(object, message = nil)
              html = ""
              unless object.nil? || object.errors.blank?
                html << "<div class='alert alert-error #{object.class.name.humanize.downcase}Errors'>\n"
                html << if message.blank?
          Severity: Minor
          Found in app/helpers/application_helper.rb - 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

          Method create has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

            def create
              if logged_in?
          
                @comment = current_user.comments.new(comment_params)
                @map = @comment.map
          Severity: Minor
          Found in app/controllers/comments_controller.rb - 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 setup has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              setup: function() {
                Glop.observe('glop:predraw', function() { $C.clear();})
                // disable default "delete" key (in Chrome it goes "back")
                window.addEventListener ('keydown', function (e) {
                  // If the key pressed was a backspace key, handle it specially
          Severity: Minor
          Found in app/assets/javascripts/knitter.js - About 1 hr to fix

            Function fetchStatusUrl has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                function fetchStatusUrl(opts) {
                  console.log('fetch status json', opts);
            
                  var scale = 0;
                  opts.collection.forEach(function(img) {
            Severity: Minor
            Found in app/assets/javascripts/mapknitter/Map.js - About 1 hr to fix

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

                saveImage: function () {
                  var img = this;
                  img._corner_state = JSON.stringify(img._corners); // reset change state string:
                  $.ajax('/images/' + img.warpable_id, { // send save request
                    type: 'PATCH',
              Severity: Minor
              Found in app/assets/javascripts/mapknitter/Map.js - About 1 hr to fix

                Method update has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def update
                    @warpable = Warpable.find(params[:warpable_id])
                
                    if Map.find(@warpable.map_id).anonymous? || logged_in?
                      nodes = []
                Severity: Minor
                Found in app/controllers/images_controller.rb - About 1 hr to fix

                  Method collect_ways has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def self.collect_ways(features)
                      # collected_ways variable unused review this function
                      collected_ways = []
                      nodes = {}
                      features['osm']['node'].each do |node|
                  Severity: Minor
                  Found in lib/cartagen.rb - About 1 hr to fix

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

                        retrieve: function(id, callback) {
                            this._retrieveResources(id, callback)
                                .done.call(this, function() {
                                    console.log('retrieved resources');
                                });
                    Severity: Minor
                    Found in app/assets/javascripts/mapknitter/core/Resources.js and 1 other location - About 55 mins to fix
                    app/assets/javascripts/mapknitter/core/Resources.js on lines 22..27

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

                    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

                        create: function(annotation, callback) {
                            this._createResource(annotation, callback)
                                .done.call(this, function() {
                                    console.log('created new resource');
                                });
                    Severity: Minor
                    Found in app/assets/javascripts/mapknitter/core/Resources.js and 1 other location - About 55 mins to fix
                    app/assets/javascripts/mapknitter/core/Resources.js on lines 15..20

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

                    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

                    Unchecked return value from xmlTextReaderExpand
                    Open

                        nokogiri (1.13.8)
                    Severity: Critical
                    Found in Gemfile.lock by bundler-audit

                    Advisory: CVE-2022-23476

                    Criticality: High

                    URL: https://github.com/sparklemotion/nokogiri/security/advisories/GHSA-qv4q-mr5r-qprj

                    Solution: upgrade to >= 1.13.10

                    Denial of Service Vulnerability in Rack Content-Disposition parsing
                    Open

                        rack (2.2.4)
                    Severity: Minor
                    Found in Gemfile.lock by bundler-audit

                    Advisory: CVE-2022-44571

                    URL: https://github.com/rack/rack/releases/tag/v3.0.4.1

                    Solution: upgrade to >= 2.0.9.2, ~> 2.0.9, >= 2.1.4.2, ~> 2.1.4, >= 2.2.6.1, ~> 2.2.6, >= 3.0.4.1

                    Inefficient Regular Expression Complexity in rails-html-sanitizer
                    Open

                        rails-html-sanitizer (1.4.3)
                    Severity: Critical
                    Found in Gemfile.lock by bundler-audit

                    Advisory: CVE-2022-23517

                    Criticality: High

                    URL: https://github.com/rails/rails-html-sanitizer/security/advisories/GHSA-5x79-w82f-gw8w

                    Solution: upgrade to >= 1.4.4

                    Possible XSS vulnerability with certain configurations of rails-html-sanitizer
                    Open

                        rails-html-sanitizer (1.4.3)
                    Severity: Minor
                    Found in Gemfile.lock by bundler-audit

                    Advisory: CVE-2022-23520

                    Criticality: Medium

                    URL: https://github.com/rails/rails-html-sanitizer/security/advisories/GHSA-rrfc-7g8p-99q8

                    Solution: upgrade to >= 1.4.4

                    Severity
                    Category
                    Status
                    Source
                    Language