hackedteam/test-av2

View on GitHub
scripts/mobile/hardware/adbclient.py

Summary

Maintainability
F
3 days
Test Coverage

File adbclient.py has 450 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'''
Copyright (C) 2012-2013  Diego Torres Milano
Created on Dec 1, 2012

Licensed under the Apache License, Version 2.0 (the "License");
Severity: Minor
Found in scripts/mobile/hardware/adbclient.py - About 6 hrs to fix

    AdbClient has 35 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class AdbClient:
    
        def __init__(self, serialno=None, hostname=HOSTNAME, port=PORT, settransport=True, reconnect=True):
            self.serialno = serialno
            self.hostname = hostname
    Severity: Minor
    Found in scripts/mobile/hardware/adbclient.py - About 4 hrs to fix

      Function shell has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def shell(self, cmd=None):
              if DEBUG:
                  print >> sys.stderr, "shell(cmd=%s)" % cmd
              if cmd:
                  self.__send('shell:%s' % cmd, checkok=True, reconnect=False)
      Severity: Minor
      Found in scripts/mobile/hardware/adbclient.py - About 2 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

      Function takeSnapshot has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def takeSnapshot(self, reconnect=False):
              '''
              Takes a snapshot of the device and return it as a PIL Image.
              '''
      
      
      Severity: Minor
      Found in scripts/mobile/hardware/adbclient.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 __send has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def __send(self, msg, checkok=True, reconnect=False):
              if DEBUG:
                  print >> sys.stderr, "__send(%s, checkok=%s, reconnect=%s)" % (msg, checkok, reconnect)
              if not re.search('^host:', msg):
                  if not self.isTransportSet:
      Severity: Minor
      Found in scripts/mobile/hardware/adbclient.py - 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

      Avoid deeply nested control flow statements.
      Open

                      if prompt.match(line):
                          break
                      print line,
      Severity: Major
      Found in scripts/mobile/hardware/adbclient.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                        if not line:
                            break
        
        
        Severity: Major
        Found in scripts/mobile/hardware/adbclient.py - About 45 mins to fix

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

              def percentSame(image1, image2):
                  '''
                  Returns the percent of pixels that are equal
          
                  @author: catshoes
          Severity: Minor
          Found in scripts/mobile/hardware/adbclient.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 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def __init__(self, serialno=None, hostname=HOSTNAME, port=PORT, settransport=True, reconnect=True):
          Severity: Minor
          Found in scripts/mobile/hardware/adbclient.py - About 35 mins to fix

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

                def __setTransport(self):
                    if DEBUG:
                        print >> sys.stderr, "__setTransport()"
                    if not self.serialno:
                        raise ValueError("serialno not set, empty or None")
            Severity: Minor
            Found in scripts/mobile/hardware/adbclient.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

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

                def longPress(self, name):
                    # WORKAROUND:
                    # Using 'input keyevent --longpress POWER' does not work correctly in
                    # KitKat (API 19), it sends a short instead of a long press.
                    # This uses the events instead, but it may vary from device to device.
            Severity: Minor
            Found in scripts/mobile/hardware/adbclient.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

                def isLocked(self):
                    '''
                    Checks if the device screen is locked.
            
                    @return True if the device screen is locked
            Severity: Major
            Found in scripts/mobile/hardware/adbclient.py and 1 other location - About 3 hrs to fix
            scripts/mobile/hardware/adbclient.py on lines 465..476

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

            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

                def isScreenOn(self):
                    '''
                    Checks if the screen is ON.
            
                    @return True if the device screen is ON
            Severity: Major
            Found in scripts/mobile/hardware/adbclient.py and 1 other location - About 3 hrs to fix
            scripts/mobile/hardware/adbclient.py on lines 452..463

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

            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

                def press(self, name, eventType=DOWN_AND_UP):
                    cmd = 'input keyevent %s' % name
                    if DEBUG:
                        print >> sys.stderr, "press(%s)" % cmd
                    self.shell(cmd)
            Severity: Major
            Found in scripts/mobile/hardware/adbclient.py and 1 other location - About 1 hr to fix
            scripts/mobile/hardware/adbclient.py on lines 358..362

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

            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 version >= 19:
                        cmd = 'input keyevent --longpress %s' % name
                        if DEBUG:
                            print >> sys.stderr, "longPress(%s)" % cmd
                        self.shell(cmd)
            Severity: Major
            Found in scripts/mobile/hardware/adbclient.py and 1 other location - About 1 hr to fix
            scripts/mobile/hardware/adbclient.py on lines 333..337

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

            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