nofxx/georuby

View on GitHub

Showing 91 of 91 total issues

File shp.rb has 599 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'date'
require 'fileutils' unless defined?(FileUtils)

module GeoRuby
  module Shp4r
Severity: Major
Found in lib/geo_ruby/shp4r/shp.rb - About 1 day to fix

    Method parse_geometry has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
    Open

        def parse_geometry(georss, with_tags)
          georss.strip!
          # check for W3CGeo first
          if georss =~ /<[^:>]*:lat\s*>([^<]*)</
            # if valid, it is W3CGeo
    Severity: Minor
    Found in lib/geo_ruby/georss.rb - About 1 day 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 get_record has 150 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def get_record(index)
            return nil if record_count <= index || index < 0
            dbf_record = @dbf.record(index)
            @shx.seek(100 + 8 * index) # 100 is the header length
            offset, length = @shx.read(8).unpack('N2')
    Severity: Major
    Found in lib/geo_ruby/shp4r/shp.rb - About 6 hrs to fix

      Class Point has 41 methods (exceeds 20 allowed). Consider refactoring.
      Open

          class Point < Geometry
            DEG2RAD = 0.0174532925199433
            HALFPI  = 1.5707963267948966
            attr_accessor :x, :y, :z, :m
            attr_reader :r, :t # radium and theta
      Severity: Minor
      Found in lib/geo_ruby/simple_features/point.rb - About 5 hrs to fix

        Method bounding_box has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
        Open

              def bounding_box
                max_x, min_x, max_y, min_y = -Float::MAX, Float::MAX, -Float::MAX, Float::MAX
                if with_z
                  max_z, min_z = -Float::MAX, Float::MAX
                  each do |geometry|
        Severity: Minor
        Found in lib/geo_ruby/simple_features/geometry_collection.rb - About 4 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

        Method bounding_box has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
        Open

              def bounding_box
                max_x = max_y = -Float::MAX
                min_x = min_y = Float::MAX
                if with_z
                  max_z, min_z = -Float::MAX, Float::MAX
        Severity: Minor
        Found in lib/geo_ruby/simple_features/line_string.rb - About 4 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

        Method parse_geometry has 111 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def parse_geometry(georss, with_tags)
              georss.strip!
              # check for W3CGeo first
              if georss =~ /<[^:>]*:lat\s*>([^<]*)</
                # if valid, it is W3CGeo
        Severity: Major
        Found in lib/geo_ruby/georss.rb - About 4 hrs to fix

          Method commit_add has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
          Open

                def commit_add(index)
                  max_x, min_x, max_y, min_y, max_z, min_z, max_m, min_m = @shp.xmax, @shp.xmin, @shp.ymax, @shp.ymin, @shp.zmax, @shp.zmin, @shp.mmax, @shp.mmin
                  @added.each do |record|
                    @dbf_io << ['20'].pack('H2')
                    @dbf.fields.each do |field|
          Severity: Minor
          Found in lib/geo_ruby/shp4r/shp.rb - About 3 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

          File point.rb has 310 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          require 'geo_ruby/simple_features/geometry'
          
          module GeoRuby
            module SimpleFeatures
              # Represents a point. It is in 3D if the Z coordinate is not +nil+.
          Severity: Minor
          Found in lib/geo_ruby/simple_features/point.rb - About 3 hrs to fix

            Method parse has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
            Open

                def parse(kml)
                  @factory.reset
                  @with_z = false
                  @parser = REXML::Parsers::PullParser.new(kml)
                  while @parser.has_next?
            Severity: Minor
            Found in lib/geo_ruby/kml.rb - About 3 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

            Class LineString has 26 methods (exceeds 20 allowed). Consider refactoring.
            Open

                class LineString < Geometry
                  # the list of points forming the line string
                  attr_reader :points
            
                  def initialize(srid = DEFAULT_SRID, with_z = false, with_m = false)
            Severity: Minor
            Found in lib/geo_ruby/simple_features/line_string.rb - About 3 hrs to fix

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

                    def as_georss(options = {})
                      dialect = options[:dialect] || :simple
                      case (dialect)
                      when :simple
                        geom_attr = ''
              Severity: Major
              Found in lib/geo_ruby/simple_features/envelope.rb and 1 other location - About 2 hrs to fix
              lib/geo_ruby/simple_features/geometry.rb on lines 123..141

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

              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

                    def as_georss(options = {})
                      dialect = options[:dialect] || :simple
                      case (dialect)
                      when :simple
                        geom_attr = ''
              Severity: Major
              Found in lib/geo_ruby/simple_features/geometry.rb and 1 other location - About 2 hrs to fix
              lib/geo_ruby/simple_features/envelope.rb on lines 83..102

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

              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 parse_coords has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
              Open

                    def parse_coords
                      coords = []
                      x = @tokenizer_structure.get_next_token
                      y = @tokenizer_structure.get_next_token
              
              
              Severity: Minor
              Found in lib/geo_ruby/ewk/ewkt_parser.rb - 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

              Method parse_coordinates has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
              Open

                  def parse_coordinates(buffer)
                    if buffer =~ /<coordinates>(.+)<\/coordinates>/m
                      Regexp.last_match[1].gsub(/\n/, ' ').strip.split(/\s+/).each do |coord|
                        x, y, z = coord.split(',')
                        if x.nil? || y.nil?
              Severity: Minor
              Found in lib/geo_ruby/kml.rb - 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

              Class Geometry has 23 methods (exceeds 20 allowed). Consider refactoring.
              Open

                  class Geometry
                    # SRID of the geometry
                    attr_reader :srid # writer defined below
                    # Flag indicating if the z ordinate of the geometry is meaningful
                    attr_accessor :with_z
              Severity: Minor
              Found in lib/geo_ruby/simple_features/geometry.rb - About 2 hrs to fix

                Method build_shp_geometry has 57 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def build_shp_geometry(geometry)
                        m_range = nil
                        answer =
                        case @shp.shp_type
                        when ShpType::POINT
                Severity: Major
                Found in lib/geo_ruby/shp4r/shp.rb - About 2 hrs to fix

                  Method human_representation has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                  Open

                        def human_representation(options = {}, g = { x: x, y: y })
                          g.map do |k, v|
                            deg = v.to_i.abs
                            min = (60 * (v.abs - deg)).to_i
                            labs = (v * 1_000_000).abs / 1_000_000
                  Severity: Minor
                  Found in lib/geo_ruby/simple_features/point.rb - 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

                  Method parse_file has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                  Open

                        def parse_file(with_z, with_m)
                          data = @gpx.read
                          @file_mode = data =~ /trkpt/ ? '//trkpt' : (data =~ /wpt/ ? '//wpt' : '//rtept')
                          Nokogiri.HTML(data).search(@file_mode).each do |tp|
                            z = z.inner_text.to_f if with_z && z = tp.at('ele')
                  Severity: Minor
                  Found in lib/geo_ruby/gpx.rb - 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

                  File ewkt_parser.rb has 252 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  require 'strscan'
                  
                  module GeoRuby
                    module SimpleFeatures
                      # Raised when an error in the EWKT string is detected
                  Severity: Minor
                  Found in lib/geo_ruby/ewk/ewkt_parser.rb - About 2 hrs to fix
                    Severity
                    Category
                    Status
                    Source
                    Language