setokinto/slack-shogi

View on GitHub
app/modules/parse_input.py

Summary

Maintainability
F
1 wk
Test Coverage

Function parse has a Cognitive Complexity of 146 (exceeds 5 allowed). Consider refactoring.
Open

    def parse(input_str, shogi):
        """
        parse input text and get (from, to) Coordinate.
        """
        is_first_turn = shogi.first
Severity: Minor
Found in app/modules/parse_input.py - About 2 days 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

Consider simplifying this complex logical expression.
Open

                    if (turn and t[0] > to_x and t[1] > to_y) or \
                       (not turn and t[0] < to_x and t[1] < to_y):
                        from_x, from_y = t
                        from_flag = 0
                        break
Severity: Major
Found in app/modules/parse_input.py - About 40 mins to fix

    Consider simplifying this complex logical expression.
    Open

                        if (turn and t[0] < to_x and t[1] > to_y) or \
                           (not turn and t[0] > to_x and t[1] < to_y):
                            from_x, from_y = t
                            from_flag = 0
                            break
    Severity: Major
    Found in app/modules/parse_input.py - About 40 mins to fix

      Consider simplifying this complex logical expression.
      Open

                          if (turn and t[0] < to_x and t[1] < to_y) or \
                             (not turn and t[0] > to_x and t[1] > to_y):
                              from_x, from_y = t
                              from_flag = 0
                              break
      Severity: Major
      Found in app/modules/parse_input.py - About 40 mins to fix

        Consider simplifying this complex logical expression.
        Open

                            if (turn and t[0] > to_x and t[1] < to_y) or \
                               (not turn and t[0] < to_x and t[1] > to_y):
                                from_x, from_y = t
                                from_flag = 0
                                break
        Severity: Major
        Found in app/modules/parse_input.py - About 40 mins to fix

          Avoid too many return statements within this function.
          Open

                      return False
          Severity: Major
          Found in app/modules/parse_input.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                            return False
            Severity: Major
            Found in app/modules/parse_input.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return False
              Severity: Major
              Found in app/modules/parse_input.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return (from_x, from_y, to_x, to_y, promote, koma)
                Severity: Major
                Found in app/modules/parse_input.py - About 30 mins to fix

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

                  str2oppkoma = {
                      "歩": Koma.opponent_fu, "と": Koma.opponent_promoted_fu,
                      "成歩": Koma.opponent_promoted_fu, "成と": Koma.opponent_promoted_fu,
                  
                      "香": Koma.opponent_kyosha, "香車": Koma.opponent_kyosha,
                  Severity: Major
                  Found in app/modules/parse_input.py and 1 other location - About 1 day to fix
                  app/modules/parse_input.py on lines 17..44

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

                  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

                  str2koma = {
                      "歩": Koma.fu, "と": Koma.promoted_fu,
                      "成歩": Koma.promoted_fu, "成と": Koma.promoted_fu,
                  
                      "香": Koma.kyosha, "香車": Koma.kyosha,
                  Severity: Major
                  Found in app/modules/parse_input.py and 1 other location - About 1 day to fix
                  app/modules/parse_input.py on lines 47..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 167.

                  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

                              elif from_flag == 2:
                                  for t in movable_komas:
                                      if (turn and t[0] > to_x) or \
                                         (not turn and t[0] < to_x):
                                          from_x, from_y = t
                  Severity: Major
                  Found in app/modules/parse_input.py and 1 other location - About 3 hrs to fix
                  app/modules/parse_input.py on lines 227..233

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

                  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

                              elif from_flag == 4:
                                  for t in movable_komas:
                                      if (turn and t[1] < to_y) or \
                                         (not turn and t[1] > to_y):
                                          from_x, from_y = t
                  Severity: Major
                  Found in app/modules/parse_input.py and 1 other location - About 3 hrs to fix
                  app/modules/parse_input.py on lines 272..278

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

                  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 from_flag == 1:
                                  for t in movable_komas:  # t => "t"arget
                                      if (turn and t[1] > to_y) or \
                                         (not turn and t[1] < to_y):
                                          from_x, from_y = t
                  Severity: Major
                  Found in app/modules/parse_input.py and 1 other location - About 3 hrs to fix
                  app/modules/parse_input.py on lines 236..242

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

                  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

                              elif from_flag == 8:
                                  for t in movable_komas:
                                      if (turn and t[0] < to_x) or \
                                         (not turn and t[0] > to_x):
                                          from_x, from_y = t
                  Severity: Major
                  Found in app/modules/parse_input.py and 1 other location - About 3 hrs to fix
                  app/modules/parse_input.py on lines 254..260

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

                  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 input_str.find("右") != -1:
                              from_flag += 2
                              input_str = input_str.replace("右", "")
                  Severity: Major
                  Found in app/modules/parse_input.py and 2 other locations - About 45 mins to fix
                  app/modules/parse_input.py on lines 168..170
                  app/modules/parse_input.py on lines 176..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 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 input_str.find("引") != -1:
                              from_flag += 4
                              input_str = input_str.replace("引", "")
                  Severity: Major
                  Found in app/modules/parse_input.py and 2 other locations - About 45 mins to fix
                  app/modules/parse_input.py on lines 162..164
                  app/modules/parse_input.py on lines 176..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 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 input_str.find("左") != -1:
                              from_flag += 8
                              input_str = input_str.replace("左", "")
                  Severity: Major
                  Found in app/modules/parse_input.py and 2 other locations - About 45 mins to fix
                  app/modules/parse_input.py on lines 162..164
                  app/modules/parse_input.py on lines 168..170

                  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 input_str.find("寄") != -1:
                              from_flag = 16
                              input_str = input_str.replace("寄", "")
                  Severity: Minor
                  Found in app/modules/parse_input.py and 2 other locations - About 35 mins to fix
                  app/modules/parse_input.py on lines 158..160
                  app/modules/parse_input.py on lines 189..191

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

                  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 input_str.find("直") != -1:
                              from_flag = 17
                              input_str = input_str.replace("直", "")
                  Severity: Minor
                  Found in app/modules/parse_input.py and 2 other locations - About 35 mins to fix
                  app/modules/parse_input.py on lines 158..160
                  app/modules/parse_input.py on lines 185..187

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

                  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 input_str.find("上") != -1:
                              from_flag = 1
                              input_str = input_str.replace("上", "")
                  Severity: Minor
                  Found in app/modules/parse_input.py and 2 other locations - About 35 mins to fix
                  app/modules/parse_input.py on lines 185..187
                  app/modules/parse_input.py on lines 189..191

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

                  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