wikimedia/pywikibot

View on GitHub
scripts/commonscat.py

Summary

Maintainability
C
1 day
Test Coverage

Function checkCommonscatLink has a Cognitive Complexity of 23 (exceeds 10 allowed). Consider refactoring.
Open

    def checkCommonscatLink(self, name: str = ''):
        """Return the name of a valid commons category.

        If the page is a redirect this function tries to follow it.
        If the page doesn't exists the function will return an empty string
Severity: Minor
Found in scripts/commonscat.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 skipPage has a Cognitive Complexity of 20 (exceeds 10 allowed). Consider refactoring.
Open

    def skipPage(page) -> bool:
        """Determine if the page should be skipped."""
        try:
            templates_to_ignore = ignoreTemplates[page.site.code]
        except KeyError:
Severity: Minor
Found in scripts/commonscat.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 treat_page has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
Open

    def treat_page(self) -> None:
        """
        Add CommonsCat template to page.

        Take a page. Go to all the interwiki page looking for a commonscat
Severity: Minor
Found in scripts/commonscat.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 main has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring.
Open

def main(*args: str) -> None:
    """
    Process command line arguments and invoke bot.

    If args is an empty list, sys.argv is used.
Severity: Minor
Found in scripts/commonscat.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 getCommonscatLink has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring.
Open

    def getCommonscatLink(page):  # noqa: N802
        """Find CommonsCat template on page.

        :rtype: tuple of (<templatename>, <target>, <linktext>, <note>)
        """
Severity: Minor
Found in scripts/commonscat.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

Avoid too many return statements within this function.
Open

            return self.checkCommonscatLink(
Severity: Major
Found in scripts/commonscat.py - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

            return commonsPage.title(with_ns=False)
    Severity: Major
    Found in scripts/commonscat.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return ''
      Severity: Major
      Found in scripts/commonscat.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return ''
        Severity: Major
        Found in scripts/commonscat.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                              return self.checkCommonscatLink(param[0])
          Severity: Major
          Found in scripts/commonscat.py - About 30 mins to fix

            TODO found
            Open

                        # TODO: if the commonsLink == '', should it be removed?
            Severity: Minor
            Found in scripts/commonscat.py by fixme

            TODO found
            Open

                        return  # TODO: handle additional param on de-wiki
            Severity: Minor
            Found in scripts/commonscat.py by fixme

            There are no issues that match your filters.

            Category
            Status