kigster/laser-cutter

View on GitHub

Showing 25 of 25 total issues

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

        def add_corners_when_out(dim_index, direction, k)
          v1 = direction * k * shift_vector(1, dim_index)
          v2 = direction * k * shift_vector(2, dim_index)
          p1 = edge.inside.p1.plus(v1)
          coords = []
Severity: Major
Found in lib/laser-cutter/notching/path_generator.rb and 1 other location - About 3 hrs to fix
lib/laser-cutter/notching/path_generator.rb on lines 118..137

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

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 add_boxes_when_in(dim_index, direction, k)
          v1 = k * direction * shift_vector(1, dim_index)
          v2 = k * direction * shift_vector(2, dim_index)
          p1 = edge.inside.p1.plus(v1)
          coords = []
Severity: Major
Found in lib/laser-cutter/notching/path_generator.rb and 1 other location - About 3 hrs to fix
lib/laser-cutter/notching/path_generator.rb on lines 140..159

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

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 has 86 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def self.parse(args)
          banner_text = <<-EOF
#{('Laser-Cutter v'+ Laser::Cutter::VERSION).bold}

Usage: laser-cutter [options] -o filename.pdf
Severity: Major
Found in lib/laser-cutter/cli/opt_parser.rb - About 3 hrs to fix

    Method render has 53 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def render pdf = nil
        banner = <<-EOF
    
        Made with Laser Cutter Ruby Gem (v#{Laser::Cutter::VERSION})
        Credits to Prawn for ruby PDF generation,
    Severity: Major
    Found in lib/laser-cutter/renderer/meta_renderer.rb - About 2 hrs to fix

      Method validate! has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

            def validate!
              missing = []
              REQUIRED.each { |k| missing << k if self[k].nil? }
              raise MissingOption.new("#{missing.join(', ')} #{missing.size > 1 ? 'are' : 'is'} required, but missing.") unless missing.empty?
      
      
      Severity: Minor
      Found in lib/laser-cutter/configuration.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 generate_notches has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def generate_notches
              position_faces!
              corner_face = pick_corners_face
              self.notches = []
              faces.each_with_index do |face, face_index|
      Severity: Minor
      Found in lib/laser-cutter/box.rb - About 1 hr to fix

        Method render has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def render
                  renderer = self
                  renderers = []
        
                  box_renderer = BoxRenderer.new(config)
        Severity: Minor
        Found in lib/laser-cutter/renderer/layout_renderer.rb - About 1 hr to fix

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

                  def define_shifts
                    along_iter = create_iterator_along
                    across_iter = create_iterator_across
          
                    shifts = []
          Severity: Minor
          Found in lib/laser-cutter/notching/path_generator.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 parse has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                  def self.parse(args)
                    banner_text = <<-EOF
          #{('Laser-Cutter v'+ Laser::Cutter::VERSION).bold}
          
          Usage: laser-cutter [options] -o filename.pdf
          Severity: Minor
          Found in lib/laser-cutter/cli/opt_parser.rb - About 55 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 serialize has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                  def serialize
                    output = if options.write_file.eql?('-')
                               $stdout
                             elsif options.write_file
                               File.open(options.write_file, 'w')
          Severity: Minor
          Found in lib/laser-cutter/cli/serializer.rb - About 55 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 change_units has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

                def change_units(new_units)
                  return if new_units.to_sym == units.to_sym
          
                  return if (units.to_sym.eql?(new_units) || !UNIT_SPECIFIC_DEFAULTS.keys.include?(new_units.to_sym))
          
          
          Severity: Minor
          Found in lib/laser-cutter/configuration.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 corner_box_sides has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

                  def corner_box_sides
                    boxes = []
                    extra_lines = []
                    sides = []
          
          
          Severity: Minor
          Found in lib/laser-cutter/notching/path_generator.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 deserialize has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

                  def deserialize
                    string = if options.read_file.eql?('-')
                               $stdin.read
                             elsif File.exist?(options.read_file)
                               File.read(options.read_file)
          Severity: Minor
          Found in lib/laser-cutter/cli/serializer.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 value_from_units has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def value_from_units value, from_units = nil
              multiplier = if from_units.nil?
                             if units.eql?('in')
                               1.0 / 72.0 # PDF units per inch
                             else
          Severity: Minor
          Found in lib/laser-cutter/page_manager.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 a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def initialize(options = {})
                  ::Hashie::Extensions::SymbolizeKeys.symbolize_keys!(options)
          
                  options.delete_if { |k, v| v.nil? }
                  if options[:units] && !UNIT_SPECIFIC_DEFAULTS.keys.include?(options[:units].to_sym)
          Severity: Minor
          Found in lib/laser-cutter/configuration.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 enclosure has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def enclosure
                  generate_notches if self.notches.empty?
                  p1 = notches.first.p1.to_a
                  p2 = notches.first.p2.to_a
          
          
          Severity: Minor
          Found in lib/laser-cutter/box.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 generate_notches has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def generate_notches
                  position_faces!
                  corner_face = pick_corners_face
                  self.notches = []
                  faces.each_with_index do |face, face_index|
          Severity: Minor
          Found in lib/laser-cutter/box.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 render has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                  def render
                    renderer = self
                    renderers = []
          
                    box_renderer = BoxRenderer.new(config)
          Severity: Minor
          Found in lib/laser-cutter/renderer/layout_renderer.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 deoverlap! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                def deoverlap!
                  lines_to_delete = []
                  lines_to_add = []
                  count = lines.size
                  for i in 0..(count - 1) do
          Severity: Minor
          Found in lib/laser-cutter/aggregator.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 initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                  def initialize(*args)
                    x = args.first
                    coordinates = if x.is_a?(String)
                      parse_string(x)
                    elsif x.is_a?(Hash)
          Severity: Minor
          Found in lib/laser-cutter/geometry/tuple.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