afast/map_print

View on GitHub

Showing 11 of 11 total issues

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

      if size && (size[:width] || size[:height])
        geometry += size[:width].to_s if size[:width]
        geometry += 'x'
        geometry += size[:height].to_s if size[:height]

Severity: Major
Found in lib/map_print/pdf_handler.rb and 1 other location - About 1 hr to fix
lib/map_print/png_handler.rb on lines 40..52

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

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

      if size && (size[:width] || size[:height])
        geometry += size[:width].to_s if size[:width]
        geometry += 'x'
        geometry += size[:height].to_s if size[:height]

Severity: Major
Found in lib/map_print/png_handler.rb and 1 other location - About 1 hr to fix
lib/map_print/pdf_handler.rb on lines 39..51

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

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

    def initialize(args)
      @format = args[:format]
      @pdf_options = args[:pdf_options]
      @png_options = args[:png_options]
      @map = args[:map]
Severity: Minor
Found in lib/map_print/core.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 print has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def print
      raise ParameterError.new('Missing png_options width attribute') unless @context.png_options && @context.png_options[:width]
      raise ParameterError.new('Missing png_options height attribute') unless @context.png_options[:height]
      `convert -density 300 -size #{@context.png_options[:width]}x#{@context.png_options[:height]} xc:#{@context.png_options[:background_color] || 'transparent'} #{@context.output_path}`
      @png = MiniMagick::Image.new @context.output_path
Severity: Minor
Found in lib/map_print/png_handler.rb - 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

Method initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def initialize(base_url, type, sw_lat_lng, ne_lat_lng, zoom)
Severity: Minor
Found in lib/map_print/tiles/tile_factory.rb - About 35 mins to fix

    Method initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def initialize(geojson, sw, ne, width, height)
    Severity: Minor
    Found in lib/map_print/geo_json_handler.rb - About 35 mins to fix

      Method next_step has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def next_step(small_step_value, big_step_value, small_step, big_step, z)
      Severity: Minor
      Found in lib/map_print/legend_handler.rb - About 35 mins to fix

        Method print_map has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def print_map
              map_image = @context.print_layers
        
              size = @context.map[:size]
              geometry = ''
        Severity: Minor
        Found in lib/map_print/pdf_handler.rb - 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

        Method print_map has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def print_map
              map_image = @context.print_layers
        
              size = @context.map[:size]
              geometry = ''
        Severity: Minor
        Found in lib/map_print/png_handler.rb - 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

        Method text_options has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def text_options(text)
                box = {}
        
                if text[:position]
                  box[:at] = text[:position].values
        Severity: Minor
        Found in lib/map_print/pdf_handlers/texts.rb - About 25 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

        Method sanitize_options has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def sanitize_options(options)
                return {} unless options.is_a?(Hash)
                options[:stroke] = options.delete :color if options[:color]
                options[:fill] = options.delete :fill_color if options[:fill_color]
                options[:gravity] ||= 'NorthWest'
        Severity: Minor
        Found in lib/map_print/png_handlers/texts.rb - About 25 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

        Severity
        Category
        Status
        Source
        Language