rubinius/rubinius

View on GitHub
core/file.rb

Summary

Maintainability
F
1 wk
Test Coverage

File file.rb has 730 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class File < IO
  include Enumerable

  class FileError < Exception; end
  class NoFileError < FileError; end
Severity: Major
Found in core/file.rb - About 1 day to fix

    Class File has 76 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class File < IO
      include Enumerable
    
      class FileError < Exception; end
      class NoFileError < FileError; end
    Severity: Major
    Found in core/file.rb - About 1 day to fix

      Method braces has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.braces(pattern, flags=0, patterns=[])
          escape = (flags & FNM_NOESCAPE) == 0
      
          rbrace = nil
          lbrace = nil
      Severity: Minor
      Found in core/file.rb - About 7 hrs 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 expand_path has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.expand_path(path, dir=nil)
          path = Rubinius::Type.coerce_to_path(path)
          str = "".force_encoding path.encoding
          first = path[0]
          if first == ?~
      Severity: Minor
      Found in core/file.rb - About 5 hrs 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 basename has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.basename(path, ext=undefined)
          path = Rubinius::Type.coerce_to_path(path)
          m = Rubinius::Mirror.reflect path
      
          slash = "/"
      Severity: Minor
      Found in core/file.rb - About 3 hrs 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 expand_path has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.expand_path(path, dir=nil)
          path = Rubinius::Type.coerce_to_path(path)
          str = "".force_encoding path.encoding
          first = path[0]
          if first == ?~
      Severity: Major
      Found in core/file.rb - About 2 hrs to fix

        Method braces has 48 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self.braces(pattern, flags=0, patterns=[])
            escape = (flags & FNM_NOESCAPE) == 0
        
            rbrace = nil
            lbrace = nil
        Severity: Minor
        Found in core/file.rb - About 1 hr to fix

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

            def self.join(*args)
              return '' if args.empty?
          
              sep = SEPARATOR
          
          
          Severity: Minor
          Found in core/file.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 initialize has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

            def initialize(path_or_fd, mode=undefined, perm=undefined, options=undefined)
              if path_or_fd.kind_of? Integer
                super(path_or_fd, mode, options)
                @path = nil
              else
          Severity: Minor
          Found in core/file.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 dirname has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.dirname(path)
              path = Rubinius::Type.coerce_to_path(path)
          
              # edge case
              return "." if path.empty?
          Severity: Minor
          Found in core/file.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 basic_realpath has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.basic_realpath(path, basedir = nil)
              path = expand_path(path, basedir || Dir.pwd)
              real = ''
              symlinks = {}
          
          
          Severity: Minor
          Found in core/file.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 basename has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.basename(path, ext=undefined)
              path = Rubinius::Type.coerce_to_path(path)
              m = Rubinius::Mirror.reflect path
          
              slash = "/"
          Severity: Minor
          Found in core/file.rb - About 1 hr to fix

            Method join has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def self.join(*args)
                return '' if args.empty?
            
                sep = SEPARATOR
            
            
            Severity: Minor
            Found in core/file.rb - About 1 hr to fix

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

                def self.identical?(orig, copy)
                  orig = Rubinius::Type.coerce_to_path(orig)
                  st_o = File::Stat.stat(orig)
                  copy = Rubinius::Type.coerce_to_path(copy)
                  st_c = File::Stat.stat(copy)
              Severity: Minor
              Found in core/file.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 utime has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.utime(a_in, m_in, *paths)
                  a_in ||= Time.now
                  a_in_usec = if a_in.is_a?(Time) || a_in.is_a?(Float) || a_in.is_a?(Rational)
                                Time.at(a_in).usec
                              else
              Severity: Minor
              Found in core/file.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 initialize has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def initialize(path_or_fd, mode=undefined, perm=undefined, options=undefined)
                  if path_or_fd.kind_of? Integer
                    super(path_or_fd, mode, options)
                    @path = nil
                  else
              Severity: Minor
              Found in core/file.rb - About 1 hr to fix

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

                  def self.lchown(owner, group, *paths)
                    raise NotImplementedError, "lchown not implemented on this platform" unless Rubinius::HAVE_LCHOWN
                
                    if owner
                      owner = Rubinius::Type.coerce_to(owner, Integer, :to_int)
                Severity: Minor
                Found in core/file.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

                Avoid deeply nested control flow statements.
                Open

                            break if pos == rbrace
                Severity: Major
                Found in core/file.rb - About 45 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return path.byteslice(0, pos)
                  Severity: Major
                  Found in core/file.rb - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                          return path.byteslice(0, idx - 1)
                    Severity: Major
                    Found in core/file.rb - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                          return false unless POSIX.access(copy, Constants::R_OK)
                      Severity: Major
                      Found in core/file.rb - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                            return false unless POSIX.access(orig, Constants::R_OK)
                        Severity: Major
                        Found in core/file.rb - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                              return "."
                          Severity: Major
                          Found in core/file.rb - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                  return path unless path.suffix? slash
                            Severity: Major
                            Found in core/file.rb - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                  return path.byteslice(dot_idx, path_size - dot_idx)
                              Severity: Major
                              Found in core/file.rb - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                      return "/" unless idx
                                Severity: Major
                                Found in core/file.rb - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                      return path
                                  Severity: Major
                                  Found in core/file.rb - About 30 mins to fix

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

                                      def self.size?(io_or_path)
                                        s = 0
                                    
                                        io = Rubinius::Type.try_convert io_or_path, IO, :to_io
                                    
                                    
                                    Severity: Minor
                                    Found in core/file.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 extname has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                      def self.extname(path)
                                        path = Rubinius::Type.coerce_to_path(path)
                                        path_size = path.bytesize
                                        m = Rubinius::Mirror.reflect path
                                    
                                    
                                    Severity: Minor
                                    Found in core/file.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 chown has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                      def self.chown(owner, group, *paths)
                                        if owner
                                          owner = Rubinius::Type.coerce_to(owner, Integer, :to_int)
                                        else
                                          owner = -1
                                    Severity: Minor
                                    Found in core/file.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 reopen has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                      def reopen(other, mode = 'r+')
                                        rewind unless closed? rescue Errno::ESPIPE
                                        unless other.kind_of? IO
                                          other = Rubinius::Type.coerce_to_path(other)
                                        end
                                    Severity: Minor
                                    Found in core/file.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

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

                                        if i
                                          nest = 0
                                    
                                          while i < pattern.size
                                            char = pattern[i]
                                    Severity: Major
                                    Found in core/file.rb and 1 other location - About 1 hr to fix
                                    core/dir_glob.rb on lines 389..414

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

                                    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

                                            while pos < rbrace and not (pattern[pos] == "," and nest == 0)
                                              nest += 1 if pattern[pos] == "{"
                                              nest -= 1 if pattern[pos] == "}"
                                    
                                              if pattern[pos] == "\\" and escape
                                    Severity: Major
                                    Found in core/file.rb and 1 other location - About 1 hr to fix
                                    core/dir_glob.rb on lines 429..439

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

                                    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

                                        if (mode & Stat::S_IROTH) == Stat::S_IROTH
                                          tmp = mode & (Stat::S_IRUGO | Stat::S_IWUGO | Stat::S_IXUGO)
                                          return Rubinius::Type.coerce_to tmp, Fixnum, :to_int
                                        end
                                    Severity: Minor
                                    Found in core/file.rb and 1 other location - About 20 mins to fix
                                    core/file.rb on lines 1082..1085

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

                                    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

                                        if (mode & Stat::S_IWOTH) == Stat::S_IWOTH
                                          tmp = mode & (Stat::S_IRUGO | Stat::S_IWUGO | Stat::S_IXUGO)
                                          return Rubinius::Type.coerce_to tmp, Fixnum, :to_int
                                        end
                                    Severity: Minor
                                    Found in core/file.rb and 1 other location - About 20 mins to fix
                                    core/file.rb on lines 1071..1074

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

                                    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