rapid7/ruby_smb

View on GitHub
lib/ruby_smb/dcerpc/ndr.rb

Summary

Maintainability
F
4 days
Test Coverage

File ndr.rb has 1018 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module RubySMB::Dcerpc::Ndr

  require 'ruby_smb/field'

  # NDR Syntax
Severity: Major
Found in lib/ruby_smb/dcerpc/ndr.rb - About 2 days to fix

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

        def do_num_bytes(struct_offset = 0, is_deferred: false)
          sum = 0
          if is_deferred
            if is_a?(NdrStruct) && self.class.superclass.has_conformant_array
              # align :max_count since it will be placed in front of the structure.
    Severity: Minor
    Found in lib/ruby_smb/dcerpc/ndr.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 extend_top_level_class has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def extend_top_level_class
          current = self
          loop do
            current.extend(TopLevelPlugin) unless current.is_a?(TopLevelPlugin)
            if current.parent.nil?
    Severity: Minor
    Found in lib/ruby_smb/dcerpc/ndr.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 fetch_alias_referent has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def fetch_alias_referent(current: parent, ref: get_parameter(:ref_to), name: nil)
          return if current.nil?
          if current.get_parameter(:ref_to) == ref
            raise ArgumentError.new(
              "Pointer alias refering to #{ref} cannot be found. This referent "\
    Severity: Minor
    Found in lib/ruby_smb/dcerpc/ndr.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 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def do_write(io, is_deferred: false)
          if is_deferred
            if is_a?(NdrStruct) && self.class.superclass.has_conformant_array
              # align :max_count since it will be placed in front of the structure.
              # The structure itself will be properly aligned later.
    Severity: Minor
    Found in lib/ruby_smb/dcerpc/ndr.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_read has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def do_read(io, is_deferred: false)
          if is_deferred
            if is_a?(NdrStruct) && self.class.superclass.has_conformant_array
              # align :max_count since it will be placed in front of the structure.
              # The structure itself will be properly aligned later.
    Severity: Minor
    Found in lib/ruby_smb/dcerpc/ndr.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 write_ref_id has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def write_ref_id(io)
          if is_alias?
            ref_field = fetch_alias_referent
            if ref_field
              if ref_field.class != self.class
    Severity: Minor
    Found in lib/ruby_smb/dcerpc/ndr.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_num_bytes has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def do_num_bytes(struct_offset = 0, is_deferred: false)
          sum = 0
          if is_deferred
            if is_a?(NdrStruct) && self.class.superclass.has_conformant_array
              # align :max_count since it will be placed in front of the structure.
    Severity: Minor
    Found in lib/ruby_smb/dcerpc/ndr.rb - About 1 hr to fix

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

          def sanitize_parameters!(obj_class, params)
            res = super
      
            type_class = params[:type]
            # Let the BinData::Array sanitization routine deal with "no type provided"
      Severity: Minor
      Found in lib/ruby_smb/dcerpc/ndr.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 assign has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def assign(val)
            if val == :null
              @ref_id = 0
            elsif is_alias?
              ref_field = fetch_alias_referent
      Severity: Minor
      Found in lib/ruby_smb/dcerpc/ndr.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 do_num_bytes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def do_num_bytes
            sum = 0
      
            if should_process_max_count?
              # count max_count (4 bytes)
      Severity: Minor
      Found in lib/ruby_smb/dcerpc/ndr.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 bytes_to_align has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def bytes_to_align(obj, rel_offset)
            if obj.is_a?(PointerPlugin)
              # Pointers are always 4-bytes aligned
              return (4 - (rel_offset % 4)) % 4
            end
      Severity: Minor
      Found in lib/ruby_smb/dcerpc/ndr.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 do_write has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def do_write(io)
            if should_process_max_count?
              max_count = retrieve_max_count
              io.writebytes([max_count].pack('L<')) if max_count
      
      
      Severity: Minor
      Found in lib/ruby_smb/dcerpc/ndr.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 do_num_bytes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def do_num_bytes(struct_offset = 0)
            sum = 0
      
            if is_a?(ConfPlugin) && should_process_max_count?
              sum += 4
      Severity: Minor
      Found in lib/ruby_smb/dcerpc/ndr.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 do_write has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def do_write(io)
            if is_a?(ConfPlugin) && should_process_max_count?
              io.writebytes([@max_count].pack('L<'))
            end
      
      
      Severity: Minor
      Found in lib/ruby_smb/dcerpc/ndr.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 method_missing has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.method_missing(symbol, *args, &block)
            field = super
            if field.is_a?(::Array) && field.last.is_a?(BinData::SanitizedField)
              unless field.last.has_parameter?(:byte_align) || field.last.instantiate.bit_aligned?
                raise ArgumentError.new(
      Severity: Minor
      Found in lib/ruby_smb/dcerpc/ndr.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 sum_num_bytes_below_index has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def sum_num_bytes_below_index(index)
            (0...index).inject(0) do |sum, i|
              nbytes = 0
              if elements[i].has_parameter?(:byte_align) && elements[i].respond_to?(:bytes_to_align)
                nbytes = elements[i].bytes_to_align(elements[i], sum.ceil)
      Severity: Minor
      Found in lib/ruby_smb/dcerpc/ndr.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

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

          unless self.const_defined?(new_klass_name)
            new_klass = Class.new(NdrConfArray) do
              default_parameters type: "ndr_#{klass}".downcase.to_sym
              extend PointerClassPlugin
            end
      Severity: Minor
      Found in lib/ruby_smb/dcerpc/ndr.rb and 1 other location - About 25 mins to fix
      lib/ruby_smb/dcerpc/ndr.rb on lines 1274..1280

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

      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

          unless self.const_defined?(new_klass_name)
            new_klass = Class.new(NdrConfVarArray) do
              default_parameters type: "ndr_#{klass}".downcase.to_sym
              extend PointerClassPlugin
            end
      Severity: Minor
      Found in lib/ruby_smb/dcerpc/ndr.rb and 1 other location - About 25 mins to fix
      lib/ruby_smb/dcerpc/ndr.rb on lines 1284..1290

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

      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

      There are no issues that match your filters.

      Category
      Status