rubyzip/rubyzip

View on GitHub
lib/zip/entry.rb

Summary

Maintainability
F
4 days
Test Coverage

File entry.rb has 632 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'pathname'

require_relative 'dirtyable'

module Zip
Severity: Major
Found in lib/zip/entry.rb - About 1 day to fix

    Class Entry has 64 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Entry
        include Dirtyable
    
        # Constant used to specify that the entry is stored (i.e., not compressed).
        STORED   = ::Zip::COMPRESSION_METHOD_STORE
    Severity: Major
    Found in lib/zip/entry.rb - About 1 day to fix

      Method create_file has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def create_file(dest_path, _continue_on_exists_proc = proc { Zip.continue_on_exists_proc })
            if ::File.exist?(dest_path) && !yield(self, dest_path)
              raise ::Zip::DestinationExistsError, dest_path
            end
      
      
      Severity: Minor
      Found in lib/zip/entry.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 pack_c_dir_entry has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def pack_c_dir_entry # :nodoc:
            zip64 = @extra['Zip64']
            [
              @header_signature,
              @version, # version of encoding software
      Severity: Minor
      Found in lib/zip/entry.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 get_input_stream has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_input_stream(&block)
            if ftype == :directory
              yield ::Zip::NullInputStream if block
              ::Zip::NullInputStream
            elsif @filepath
      Severity: Minor
      Found in lib/zip/entry.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 prep_cdir_zip64_extra has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def prep_cdir_zip64_extra
            return unless ::Zip.write_zip64_support
      
            if (@size && @size >= 0xFFFFFFFF) || @compressed_size >= 0xFFFFFFFF ||
               @local_header_offset >= 0xFFFFFFFF
      Severity: Minor
      Found in lib/zip/entry.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 read_local_entry has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def read_local_entry(io) # :nodoc:
            @dirty = false # No changes at this point.
            @local_header_offset = io.tell
      
            static_sized_fields_buf = io.read(::Zip::LOCAL_ENTRY_STATIC_HEADER_LENGTH) || ''
      Severity: Minor
      Found in lib/zip/entry.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_c_dir_entry has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def write_c_dir_entry(io) # :nodoc:
            prep_cdir_zip64_extra
      
            case @fstype
            when ::Zip::FSTYPE_UNIX
      Severity: Minor
      Found in lib/zip/entry.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 get_input_stream has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def get_input_stream(&block)
            if ftype == :directory
              yield ::Zip::NullInputStream if block
              ::Zip::NullInputStream
            elsif @filepath
      Severity: Minor
      Found in lib/zip/entry.rb - About 1 hr to fix

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

            def set_ftype_from_c_dir_entry # :nodoc:
              @ftype = case @fstype
                       when ::Zip::FSTYPE_UNIX
                         @unix_perms = (@external_file_attributes >> 16) & 0o7777
                         case (@external_file_attributes >> 28)
        Severity: Minor
        Found in lib/zip/entry.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 read_local_entry has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def read_local_entry(io) # :nodoc:
              @dirty = false # No changes at this point.
              @local_header_offset = io.tell
        
              static_sized_fields_buf = io.read(::Zip::LOCAL_ENTRY_STATIC_HEADER_LENGTH) || ''
        Severity: Minor
        Found in lib/zip/entry.rb - About 1 hr to fix

          Method pack_local_entry has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def pack_local_entry # :nodoc:
                zip64 = @extra['Zip64']
                [::Zip::LOCAL_ENTRY_SIGNATURE,
                 @version_needed_to_extract, # version needed to extract
                 @gp_flags, # @gp_flags
          Severity: Minor
          Found in lib/zip/entry.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 gather_fileinfo_from_srcpath has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def gather_fileinfo_from_srcpath(src_path) # :nodoc:
                stat   = file_stat(src_path)
                @ftype = case stat.ftype
                         when 'file'
                           if name_is_directory?
          Severity: Minor
          Found in lib/zip/entry.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

          Consider simplifying this complex logical expression.
          Open

                if zip64? || @size.nil? || @size >= 0xFFFFFFFF || @compressed_size >= 0xFFFFFFFF
                  @version_needed_to_extract = VERSION_NEEDED_TO_EXTRACT_ZIP64
                  zip64 = @extra['Zip64'] || @extra.create('Zip64')
          
                  # Local header always includes size and compressed size.
          Severity: Major
          Found in lib/zip/entry.rb - About 40 mins to fix

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

                def initialize(
                  zipfile = '', name = '',
                  comment: '', size: nil, compressed_size: 0, crc: 0,
                  compression_method: DEFLATED,
                  compression_level: ::Zip.default_compression,
            Severity: Minor
            Found in lib/zip/entry.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 extract has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def extract(entry_path = @name, destination_directory: '.', &block)
                  dest_dir = ::File.absolute_path(destination_directory || '.')
                  extract_path = ::File.absolute_path(::File.join(dest_dir, entry_path))
            
                  unless extract_path.start_with?(dest_dir)
            Severity: Minor
            Found in lib/zip/entry.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 prep_local_zip64_extra has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def prep_local_zip64_extra
                  return unless ::Zip.write_zip64_support
                  return if (!zip64? && @size && @size < 0xFFFFFFFF) || !file?
            
                  # Might not know size here, so need ZIP64 just in case.
            Severity: Minor
            Found in lib/zip/entry.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 create_directory has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def create_directory(dest_path)
                  return if ::File.directory?(dest_path)
            
                  if ::File.exist?(dest_path)
                    raise ::Zip::DestinationExistsError, dest_path unless block_given? && yield(self, dest_path)
            Severity: Minor
            Found in lib/zip/entry.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 time= has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def time=(value, component: :mtime)
                  @dirty = true
                  unless @extra.member?('UniversalTime') || @extra.member?('NTFS')
                    @extra.create('UniversalTime')
                  end
            Severity: Minor
            Found in lib/zip/entry.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