hackedteam/vector-edk

View on GitHub
BaseTools/Source/Python/Common/Expression.py

Summary

Maintainability
F
4 days
Test Coverage

File Expression.py has 482 lines of code (exceeds 250 allowed). Consider refactoring.
Open

## @file
# This file is used to parse and evaluate expression in directive or PCD value.
#
# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
Severity: Minor
Found in BaseTools/Source/Python/Common/Expression.py - About 7 hrs to fix

    Function Eval has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

        def Eval(Operator, Oprand1, Oprand2 = None):
            WrnExp = None
    
            if Operator not in ["==", "!=", ">=", "<=", ">", "<", "in", "not in"] and \
                (type(Oprand1) == type('') or type(Oprand2) == type('')):
    Severity: Minor
    Found in BaseTools/Source/Python/Common/Expression.py - 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

    Function ReplaceExprMacro has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

    def ReplaceExprMacro(String, Macros, ExceptionList = None):
        StrList = SplitString(String)
        for i, String in enumerate(StrList):
            InQuote = False
            if String.startswith('"'):
    Severity: Minor
    Found in BaseTools/Source/Python/Common/Expression.py - 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

    ValueExpression has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ValueExpression(object):
        # Logical operator mapping
        LogicalOperators = {
            '&&' : 'and', '||' : 'or',
            '!'  : 'not', 'AND': 'and',
    Severity: Minor
    Found in BaseTools/Source/Python/Common/Expression.py - About 3 hrs to fix

      Function __call__ has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          def __call__(self, RealValue=False, Depth=0):
              if self._NoProcess:
                  return self._Expr
      
              self._Depth = Depth
      Severity: Minor
      Found in BaseTools/Source/Python/Common/Expression.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 _GetOperator has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def _GetOperator(self):
              self.__SkipWS()
              LegalOpLst = ['&&', '||', '!=', '==', '>=', '<='] + self.NonLetterOpLst
      
              self._Token = ''
      Severity: Minor
      Found in BaseTools/Source/Python/Common/Expression.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 SplitString has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      def SplitString(String):
          # There might be escaped quote: "abc\"def\\\"ghi"
          Str = String.replace('\\\\', '//').replace('\\\"', '\\\'')
          RetList = []
          InQuote = False
      Severity: Minor
      Found in BaseTools/Source/Python/Common/Expression.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 _GetSingleToken has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def _GetSingleToken(self):
              self.__SkipWS()
              Expr = self._Expr[self._Idx:]
              if Expr.startswith('L"'):
                  # Skip L
      Severity: Minor
      Found in BaseTools/Source/Python/Common/Expression.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 __GetArray has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def __GetArray(self):
              Token = '{'
              self._Idx += 1
              self.__GetNList(True)
              Token += self._LiteralToken
      Severity: Minor
      Found in BaseTools/Source/Python/Common/Expression.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 __ResolveToken has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def __ResolveToken(self):
              if not self._Token:
                  raise BadExpression(ERR_EMPTY_TOKEN)
      
              # PCD token
      Severity: Minor
      Found in BaseTools/Source/Python/Common/Expression.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 _EqExpr has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def _EqExpr(self):
              Val = self._RelExpr()
              while self._IsOperator(["==", "!=", "EQ", "NE", "IN", "in", "!", "NOT", "not"]):
                  Op = self._Token
                  if Op in ["!", "NOT", "not"]:
      Severity: Minor
      Found in BaseTools/Source/Python/Common/Expression.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 __GetNList has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def __GetNList(self, InArray=False):
              self._GetSingleToken()
              if not self.__IsHexLiteral():
                  if InArray:
                      raise BadExpression(ERR_ARRAY_ELE % self._Token)
      Severity: Minor
      Found in BaseTools/Source/Python/Common/Expression.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 self.__GetArray()
      Severity: Major
      Found in BaseTools/Source/Python/Common/Expression.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                        return self._Token
        Severity: Major
        Found in BaseTools/Source/Python/Common/Expression.py - About 30 mins to fix

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

                          if Operator in ["==", "!=", ">=", "<=", ">", "<"] and set((TypeDict[type(Oprand1)], TypeDict[type(Oprand2)])) == set((TypeDict[type(True)], TypeDict[type(0)])):
          Severity: Major
          Found in BaseTools/Source/Python/Common/Expression.py and 1 other location - About 2 hrs to fix
          BaseTools/Source/Python/Common/Expression.py on lines 181..181

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

          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

                          elif Operator in ['&', '|', '^', "and", "or"] and set((TypeDict[type(Oprand1)], TypeDict[type(Oprand2)])) == set((TypeDict[type(True)], TypeDict[type(0)])):
          Severity: Major
          Found in BaseTools/Source/Python/Common/Expression.py and 1 other location - About 2 hrs to fix
          BaseTools/Source/Python/Common/Expression.py on lines 178..178

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

          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 3 locations. Consider refactoring.
          Open

              def __SkipWS(self):
                  for Char in self._Expr[self._Idx:]:
                      if Char not in ' \t':
                          break
                      self._Idx += 1
          Severity: Major
          Found in BaseTools/Source/Python/Common/Expression.py and 2 other locations - About 1 hr to fix
          BaseTools/Source/Python/UPT/Library/ExpressionValidate.py on lines 88..92
          BaseTools/Source/Python/UPT/Parser/DecParserMisc.py on lines 299..303

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

          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