hackedteam/vector-edk

View on GitHub
AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.py

Summary

Maintainability
F
5 days
Test Coverage

File webchecker.py has 671 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#! /usr/bin/env python

# Original code by Guido van Rossum; extensive changes by Sam Bayer,
# including code to check URL fragments.

    Function main has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
    Open

    def main():
        checkext = CHECKEXT
        verbose = VERBOSE
        maxpage = MAXPAGE
        roundsize = ROUNDSIZE

    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

    Checker has 34 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Checker:
    
        checkext = CHECKEXT
        verbose = VERBOSE
        maxpage = MAXPAGE

      MyHTMLParser has 21 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class MyHTMLParser(sgmllib.SGMLParser):
      
          def __init__(self, url, verbose=VERBOSE, checker=None):
              self.myverbose = verbose # now unused
              self.checker = checker

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

            def do_base(self, attributes):
                for name, value in attributes:
                    if name == 'href':
                        if value: value = value.strip()
                        if value:

        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 dopage has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def dopage(self, url_pair):
        
                # All printing of URLs uses format_url(); argument changed to
                # url_pair for clarity.
                if self.verbose > 1:

        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 report_errors has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def report_errors(self):
                if not self.bad:
                    self.message("\nNo errors")
                    return
                self.message("\nError Report:")

        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 open_file has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def open_file(self, url):
                path = urllib.url2pathname(urllib.unquote(url))
                if os.path.isdir(path):
                    if path[-1] != os.sep:
                        url = url + '/'
        Severity: Minor
        Found in AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.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

        Function link_attr has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def link_attr(self, attributes, *args):
                for name, value in attributes:
                    if name in args:
                        if value: value = value.strip()
                        if value: self.links[value] = None
        Severity: Minor
        Found in AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.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

        Function getpage has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def getpage(self, url_pair):
                # Incoming argument name is a (URL, fragment) pair.
                # The page may have been cached in the name_table variable.
                url, fragment = url_pair
                if self.name_table.has_key(url):
        Severity: Minor
        Found in AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.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

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

            def note(self, level, msg, *args):
                if self.checker:
                    apply(self.checker.note, (level, msg) + args)
                else:
                    if self.verbose >= level:
        Severity: Minor
        Found in AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.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 checkforhtml has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def checkforhtml(self, info, url):
                if info.has_key('content-type'):
                    ctype = cgi.parse_header(info['content-type'])[0].lower()
                    if ';' in ctype:
                        # handle content-type: text/html; charset=iso8859-1 :
        Severity: Minor
        Found in AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.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 http_error_401 has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def http_error_401(self, url, fp, errcode, errmsg, headers):
        Severity: Minor
        Found in AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.py - About 35 mins to fix

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

              def __init__(self, text, url, verbose=VERBOSE, maxpage=MAXPAGE, checker=None):
          Severity: Minor
          Found in AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.py - About 35 mins to fix

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

                def check_name_id(self, attributes):
                    """ Check the name or id attributes on an element.
                    """
                    # We must rescue the NAME or id (name is deprecated in XHTML)
                    # attributes from the anchor, in order to
            Severity: Minor
            Found in AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.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 do_link has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def do_link(self, attributes):
                    for name, value in attributes:
                        if name == "rel":
                            parts = value.lower().split()
                            if (  parts == ["stylesheet"]
            Severity: Minor
            Found in AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.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 Page(text, url, maxpage=self.maxpage, checker=self)
            Severity: Major
            Found in AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.py - About 30 mins to fix

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

                  def show(self, p1, link, p2, origins):
                      self.message("%s %s", p1, link)
                      i = 0
                      for source, rawlink in origins:
                          i = i+1
              Severity: Minor
              Found in AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.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

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

              if __version__[0] == '$':
                  _v = __version__.split()
                  if len(_v) == 3:
                      __version__ = _v[1]
              AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/websucker.py on lines 15..18

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

              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 not checkext:
                      for root in extra_roots:
                          # Make sure it's terminated by a slash,
                          # so that addroot doesn't discard the last
                          # directory component.
              AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/wcgui.py on lines 102..108

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

                          if origin not in self.todo[url]:
                              self.todo[url].append(origin)
              AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.py on lines 441..442
              AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.py on lines 592..599

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

                      if origin not in self.done[url]:
                          self.done[url].append(origin)
              AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.py on lines 458..459
              AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.py on lines 592..599

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

                      try:
                          # Because of the way the URLs are now processed, I need to
                          # check to make sure the URL hasn't been entered in the
                          # error list.  The first element of the triple here is a
                          # (URL, fragment) pair, but the URL key is not, since it's
              AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.py on lines 441..442
              AppPkg/Applications/Python/Python-2.7.2/Tools/webchecker/webchecker.py on lines 458..459

              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