hackedteam/core-android-market

View on GitHub
server/benews-srv.py

Summary

Maintainability
F
5 days
Test Coverage

Function get_next_news has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
Open

def get_next_news(client_param,client_stats):
    nline = 0;
    #printl("opening file %s" %batch_file)
    if os.path.exists(batch_file) and len(echo.translated_lines) == 0:
        opened = open(batch_file)
Severity: Minor
Found in server/benews-srv.py - About 1 day 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 extract_news_from_line has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

def extract_news_from_line(line):
#Date|Title|headline|content|type|filepath|imei|trials
    news = None
    line = line.rstrip()
    news_item = line.split("|")
Severity: Minor
Found in server/benews-srv.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 echo has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

def echo(socket, address):

    printl('New connection from %s:%s' % address)
    (ip, port) = address
    data = None
Severity: Minor
Found in server/benews-srv.py - About 4 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

File benews-srv.py has 314 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python
"""Simple server that listens on port 6954 and replies with a bson encoded news

Connect to it with:
nc localhost 6954
Severity: Minor
Found in server/benews-srv.py - About 3 hrs to fix

    Function is_ts_valid has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def is_ts_valid(ts, client_ts, trial, client_trial, client_cks=None):
        if ts and client_ts is not None and ts.isdigit():
            if client_ts == int(ts) and ( client_cks and (client_cks == "-2" or ( client_cks != "-3" and client_cks != "0" and client_cks != "-1" )) ):
                if trial is not None and trial.isdigit() and client_trial < int(trial):
                    printl("is_ts_valid:more trials")
    Severity: Minor
    Found in server/benews-srv.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 deeply nested control flow statements.
    Open

                        if not news['date'] or not news['date'].isdigit():
                            printl("Invalid date field not present or not a digit")
                            news = None
                        if not news['filepath'] or not os.path.exists(news['filepath']):
    Severity: Major
    Found in server/benews-srv.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if not news['filepath'] or not os.path.exists(news['filepath']):
                              printl("Invalid filepath field not present or file not available")
                              news = None
          return news
      Severity: Major
      Found in server/benews-srv.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if client_param['lts_status'] == "-1":
                                    printl("Executed %s" % echo.next_news['filepath'])
                                    news = None
                                    continue
                                if client_param['lts_status'] == "-2":
        Severity: Major
        Found in server/benews-srv.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if client_param['lts_status'] != "0":
                                      printl("Failed to Send %s" % echo.next_news['filepath'])
                                  if client_param['lts_status'] == "0":
          Severity: Major
          Found in server/benews-srv.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if res_date == 1:
                                    news = {'date': news_item[0], 'title': news_item[1], 'headline': news_item[2], 'content': news_item[3],
                                            'type': news_item[4], 'filepath': news_item[5], 'imei': news_item[6], 'trials': news_item[7]}
                                else:
                                    news_item[0] = ' '.join(news_item[0].split())
            Severity: Major
            Found in server/benews-srv.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if client_param['lts_status'] == "0":
                                          printl("Correctly Sent %s" % echo.next_news['filepath'])
                                          news = None
                                          continue
                              now = time.time()
              Severity: Major
              Found in server/benews-srv.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        if client_param['lts_status'] == "-3":
                                            printl("Running %s" % echo.next_news['filepath'])
                                            return echo.next_news
                                        if client_param['lts_status'] == "-1":
                Severity: Major
                Found in server/benews-srv.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          if client_param['lts_status'] == "-2":
                                              printl("Failed to Execute %s" % echo.next_news['filepath'])
                                          if client_param['lts_status'] != "0":
                  Severity: Major
                  Found in server/benews-srv.py - About 45 mins to fix

                    Consider simplifying this complex logical expression.
                    Open

                            if client_ts == int(ts) and ( client_cks and (client_cks == "-2" or ( client_cks != "-3" and client_cks != "0" and client_cks != "-1" )) ):
                                if trial is not None and trial.isdigit() and client_trial < int(trial):
                                    printl("is_ts_valid:more trials")
                                    return True
                                else:
                    Severity: Major
                    Found in server/benews-srv.py - About 40 mins to fix

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

                      def is_ts_valid(ts, client_ts, trial, client_trial, client_cks=None):
                      Severity: Minor
                      Found in server/benews-srv.py - About 35 mins to fix

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

                        def validate_date(date_text):
                            tokens=date_text.split(" ")
                            if len(tokens) == 2:
                                try:
                                    datetime.datetime.strptime(tokens[0], '%d-%m-%Y')
                        Severity: Minor
                        Found in server/benews-srv.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

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

                        def is_imei_valid(imei, client_imei):
                            if imei and client_imei:
                                if imei == client_imei:
                                    return True
                                else:
                        Severity: Minor
                        Found in server/benews-srv.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

                        def check_dir(dir):
                            if not os.path.exists(dir):
                                d = os.mkdir(dir)
                            if os.path.exists(dir):
                                return True
                        Severity: Major
                        Found in server/benews-srv.py and 1 other location - About 2 hrs to fix
                        utils/encript.py on lines 76..81

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

                        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

                                        clients[client_param['imei']]['lts'] = int(clients[client_param['imei']]['lts']) + 1
                        Severity: Major
                        Found in server/benews-srv.py and 1 other location - About 2 hrs to fix
                        server/benews-srv.py on lines 329..329

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

                        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

                                    clients[client_param['imei']]['ts_trial'] = int(clients[client_param['imei']]['ts_trial']) + 1
                        Severity: Major
                        Found in server/benews-srv.py and 1 other location - About 2 hrs to fix
                        server/benews-srv.py on lines 298..298

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

                        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 client_param['lts_status'] == "0":
                                                    printl("Correctly Sent %s" % echo.next_news['filepath'])
                                                    news = None
                                                    continue
                        Severity: Major
                        Found in server/benews-srv.py and 1 other location - About 1 hr to fix
                        server/benews-srv.py on lines 129..132

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

                        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 client_param['lts_status'] == "-1":
                                                    printl("Executed %s" % echo.next_news['filepath'])
                                                    news = None
                                                    continue
                        Severity: Major
                        Found in server/benews-srv.py and 1 other location - About 1 hr to fix
                        server/benews-srv.py on lines 137..140

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

                        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