dmendel/bindata

View on GitHub
lib/bindata/struct.rb

Summary

Maintainability
C
1 day
Test Coverage

Class Struct has 34 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Struct < BinData::Base
    arg_processor :struct

    mandatory_parameter :fields
    optional_parameters :endian, :search_prefix, :hide
Severity: Minor
Found in lib/bindata/struct.rb - About 4 hrs to fix

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

    require 'bindata/base'
    require 'bindata/delayed_io'
    
    module BinData
      class Base
    Severity: Minor
    Found in lib/bindata/struct.rb - About 3 hrs to fix

      Method sum_num_bytes_below_index has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

            def sum_num_bytes_below_index(index)
              sum = 0
              @field_objs.each_with_index do |obj, i|
                next unless include_obj?(obj)
      
      
      Severity: Minor
      Found in lib/bindata/struct.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 do_write has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

            def do_write(io)
              offset = 0
              instantiate_all_objs
              @field_objs.each do |f|
                next unless include_obj?(f)
      Severity: Minor
      Found in lib/bindata/struct.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 do_read has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

            def do_read(io)
              offset = 0
              instantiate_all_objs
              @field_objs.each do |f|
                next unless include_obj?(f)
      Severity: Minor
      Found in lib/bindata/struct.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 sum_num_bytes_below_index has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def sum_num_bytes_below_index(index)
            (0...index).inject(0) do |sum, i|
              obj = @field_objs[i]
              if include_obj?(obj)
                nbytes = obj.do_num_bytes
      Severity: Minor
      Found in lib/bindata/struct.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 ensure_field_names_are_valid has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def ensure_field_names_are_valid(obj_class, field_names)
            reserved_names = BinData::Struct::RESERVED
      
            field_names.each do |name|
              if obj_class.method_defined?(name)
      Severity: Minor
      Found in lib/bindata/struct.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 define_field_accessors_for has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def define_field_accessors_for(name, index)
            define_singleton_method(name) do
              instantiate_obj_at(index) if @field_objs[index].nil?
              @field_objs[index]
            end
      Severity: Minor
      Found in lib/bindata/struct.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

      There are no issues that match your filters.

      Category
      Status