bkimminich/kata-tcg

View on GitHub

Showing 9 of 11 total issues

Function playTurn has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

    playTurn: function () {
        while (hasEnoughManaForCardInHand.call(this)) {
            var choice = window.prompt(this.activePlayer + ", please choose a card to play from " + this.activePlayer.hand);
            if (choice) {
                var chosenCard = parseInt(choice, 10);
Severity: Minor
Found in tcg-js/js/game.js - 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

Function playTurn has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    playTurn: function () {
        while (hasEnoughManaForCardInHand.call(this)) {
            var choice = window.prompt(this.activePlayer + ", please choose a card to play from " + this.activePlayer.hand);
            if (choice) {
                var chosenCard = parseInt(choice, 10);
Severity: Minor
Found in tcg-js/js/game.js - About 1 hr to fix

    Avoid deeply nested control flow statements.
    Open

                        if (!window.confirm("Cannot play card " + chosenCard + " with only " + this.activePlayer.mana + " mana!")) {
                            return;
                        }
    Severity: Major
    Found in tcg-js/js/game.js - About 45 mins to fix

      Method equals has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          @Override
          public boolean equals(Object o) {
              if (this == o) return true;
              if (o == null || getClass() != o.getClass()) return false;
      
      
      Severity: Minor
      Found in tcg-java/src/main/java/de/kimminich/kata/tcg/Move.java - 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

      Avoid deeply nested control flow statements.
      Open

                      } else if (this.activePlayer.hand.indexOf(chosenCard) == -1) {
                          if (!window.confirm(chosenCard + " is not present in hand!")) {
                              return;
                          }
                      } else {
      Severity: Major
      Found in tcg-js/js/game.js - About 45 mins to fix

        Method run has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            public void run() {
                while (true) {
                    if (getWinner() == null) {
                        beginTurn();
                        while (activePlayer.canPlayCards()) {
        Severity: Minor
        Found in tcg-java/src/main/java/de/kimminich/kata/tcg/Game.java - 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

        Method nextMove has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            @Override
            public Move nextMove(int availableMana, int currentHealth, List<Card> availableCards) {
                try {
                    BufferedReader br = new BufferedReader(new InputStreamReader(System.in, Charset.defaultCharset()));
                    Integer card = -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

        Avoid too many return statements within this method.
        Open

                return true;
        Severity: Major
        Found in tcg-java/src/main/java/de/kimminich/kata/tcg/Move.java - About 30 mins to fix

          Method bestCard has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              private Optional<Card> bestCard(int availableMana, List<Card> availableCards) {
                  List<List<Card>> cardCombos = new ArrayList<>();
                  List<Card> remainingCards = new ArrayList<>(availableCards);
                  remainingCards.sort(Comparator.<Card>reverseOrder()); // highest mana costs first
                  while (!remainingCards.isEmpty()) {
          Severity: Minor
          Found in tcg-java/src/main/java/de/kimminich/kata/tcg/strategy/AiStrategy.java - 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

          Severity
          Category
          Status
          Source
          Language