ducky/streams.py

Summary

Maintainability
F
3 days
Test Coverage

File streams.py has 277 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Streams represent basic IO objects, used by devices for reading or writing
(streams) of data.

``Stream`` object encapsulates an actual IO object - ``file``-like stream,
Severity: Minor
Found in ducky/streams.py - About 2 hrs to fix

    Function __init__ has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      def __init__(self, machine, **kwargs):
        DEBUG = machine.LOGGER.debug
    
        self.old_termios = None
    
    
    Severity: Minor
    Found in ducky/streams.py - 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

    Function _raw_write_stream has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def _raw_write_stream(self, data):
        self.DEBUG('%s._raw_write_stream: data="%s", len=%s, type=%s', self.__class__.__name__, data, len(data), type(data))
    
        remaining_chars = len(data)
    
    
    Severity: Minor
    Found in ducky/streams.py - 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

    Function __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def __init__(self, machine, desc, stream = None, fd = None, close = True, allow_close = True):
    Severity: Minor
    Found in ducky/streams.py - About 45 mins to fix

      Function create has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def create(machine, desc):
          machine.LOGGER.debug('OutputStream.create: desc=%s', desc)
      
          if isfile(desc):
            return FileOutputStream(machine, desc)
      Severity: Minor
      Found in ducky/streams.py - 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

      Avoid too many return statements within this function.
      Open

            return StdinStream(machine)
      Severity: Major
      Found in ducky/streams.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

              return FileOutputStream(machine, open(desc, 'wb'))
        Severity: Major
        Found in ducky/streams.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                return FileInputStream(machine, open(desc, 'rb'))
          Severity: Major
          Found in ducky/streams.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                  return StdoutStream(machine)
            Severity: Major
            Found in ducky/streams.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                    return StderrStream(machine)
              Severity: Major
              Found in ducky/streams.py - About 30 mins to fix

                Function create has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def create(machine, desc):
                    machine.LOGGER.debug('InputStream.create: desc=%s', desc)
                
                    if isfile(desc):
                      return FileInputStream(machine, desc)
                Severity: Minor
                Found in ducky/streams.py - 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

                class StdoutStream(OutputStream):
                  def __init__(self, machine):
                    stream = machine.stdout.buffer if hasattr(machine.stdout, 'buffer') else machine.stdout
                    fd = machine.stdout.fileno() if hasattr(machine.stdout, 'fileno') else None
                
                
                Severity: Major
                Found in ducky/streams.py and 1 other location - About 4 hrs to fix
                ducky/streams.py on lines 386..391

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

                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

                class StderrStream(OutputStream):
                  def __init__(self, machine):
                    stream = machine.stderr.buffer if hasattr(machine.stderr, 'buffer') else machine.stderr
                    fd = machine.stderr.fileno() if hasattr(machine.stderr, 'fileno') else None
                
                
                Severity: Major
                Found in ducky/streams.py and 1 other location - About 4 hrs to fix
                ducky/streams.py on lines 379..384

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

                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

                class FileOutputStream(OutputStream):
                  def __init__(self, machine, f, **kwargs):
                    super(FileOutputStream, self).__init__(machine, '<file %s>' % f.name, stream = f, fd = f.fileno())
                Severity: Major
                Found in ducky/streams.py and 1 other location - About 1 hr to fix
                ducky/streams.py on lines 259..261

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

                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

                class FileInputStream(InputStream):
                  def __init__(self, machine, f, **kwargs):
                    super(FileInputStream, self).__init__(machine, '<file %s>' % f.name, stream = f, fd = f.fileno())
                Severity: Major
                Found in ducky/streams.py and 1 other location - About 1 hr to fix
                ducky/streams.py on lines 367..369

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

                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

                class FDOutputStream(OutputStream):
                  def __init__(self, machine, fd, **kwargs):
                    super(FDOutputStream, self).__init__(machine, '<fd %s>' % fd, fd = fd)
                Severity: Minor
                Found in ducky/streams.py and 1 other location - About 55 mins to fix
                ducky/streams.py on lines 267..269

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

                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

                class FDInputStream(InputStream):
                  def __init__(self, machine, fd, **kwargs):
                    super(FDInputStream, self).__init__(machine, '<fd %s>' % fd, fd = fd)
                Severity: Minor
                Found in ducky/streams.py and 1 other location - About 55 mins to fix
                ducky/streams.py on lines 371..373

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

                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

                class MethodInputStream(InputStream):
                  def __init__(self, machine, desc, **kwargs):
                    super(MethodInputStream, self).__init__(machine, repr(desc), stream = desc)
                Severity: Minor
                Found in ducky/streams.py and 1 other location - About 45 mins to fix
                ducky/streams.py on lines 375..377

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

                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

                class MethodOutputStream(OutputStream):
                  def __init__(self, machine, desc, **kwargs):
                    super(MethodOutputStream, self).__init__(machine, repr(desc), stream = desc)
                Severity: Minor
                Found in ducky/streams.py and 1 other location - About 45 mins to fix
                ducky/streams.py on lines 263..265

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

                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