jcbantuelle/dominion-meteor

View on GitHub
app/game/server/services/card_player.js

Summary

Maintainability
F
3 days
Test Coverage

Function update_phase has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

  update_phase(free_play) {
    if (!free_play) {
      let phase
      if (this.game.turn.phase === 'action' && _.includes(_.words(this.card.types), 'treasure')) {
        phase = 'treasure'
Severity: Minor
Found in app/game/server/services/card_player.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 update_phase has 68 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  update_phase(free_play) {
    if (!free_play) {
      let phase
      if (this.game.turn.phase === 'action' && _.includes(_.words(this.card.types), 'treasure')) {
        phase = 'treasure'
Severity: Major
Found in app/game/server/services/card_player.js - About 2 hrs to fix

    `` has 22 functions (exceeds 20 allowed). Consider refactoring.
    Open

    CardPlayer = class CardPlayer {
    
      constructor(game, player_cards, card, originating_card) {
        this.game = game
        this.player_cards = player_cards
    Severity: Minor
    Found in app/game/server/services/card_player.js - About 2 hrs to fix

      File card_player.js has 258 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      CardPlayer = class CardPlayer {
      
        constructor(game, player_cards, card, originating_card) {
          this.game = game
          this.player_cards = player_cards
      Severity: Minor
      Found in app/game/server/services/card_player.js - About 2 hrs to fix

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

          play_card(announce, free_play) {
            let play_result
            this.token_effects()
            if (_.includes(_.words(this.card.types), 'action') && this.game.turn.player._id === this.player_cards.player_id) {
              this.game.turn.played_actions.push(this.card)
        Severity: Minor
        Found in app/game/server/services/card_player.js - 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 play_card has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          play_card(announce, free_play) {
            let play_result
            this.token_effects()
            if (_.includes(_.words(this.card.types), 'action') && this.game.turn.player._id === this.player_cards.player_id) {
              this.game.turn.played_actions.push(this.card)
        Severity: Minor
        Found in app/game/server/services/card_player.js - About 1 hr to fix

          Function play has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            play(free_play = false, move_card = true, source = 'hand', number_of_times = 1, announce = true) {
              let duration = false
              _.times(number_of_times, (play_count) => {
                if (this.can_play(free_play)) {
                  this.update_phase(free_play)
          Severity: Minor
          Found in app/game/server/services/card_player.js - About 1 hr to fix

            Avoid deeply nested control flow statements.
            Open

                    if (this.game.turn.phase === 'action') {
                      this.game.turn.phase = 'treasure'
                      let start_buy_event_processor = new StartBuyEventProcessor(this.game, this.player_cards)
                      start_buy_event_processor.process()
                    }
            Severity: Major
            Found in app/game/server/services/card_player.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                      if (_.includes(['treasure', 'buy'], this.game.turn.phase)) {
                        this.game.turn.phase = 'buy'
                        let end_buy_event_processor = new EndBuyEventProcessor(this.game, this.player_cards)
                        end_buy_event_processor.process()
                      }
              Severity: Major
              Found in app/game/server/services/card_player.js - About 45 mins to fix

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

                        if (_.includes(_.words(this.card.types), 'action') && this.game.turn.actions > 0) {
                          let turn_event_id = TurnEventModel.insert({
                            game_id: this.game._id,
                            player_id: this.player_cards.player_id,
                            username: this.player_cards.username,
                Severity: Major
                Found in app/game/server/services/card_player.js and 1 other location - About 5 hrs to fix
                app/game/server/services/lib/card_buyer.js on lines 54..72

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

                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 (this.game.turn.phase === 'action') {
                          this.game.turn.phase = 'treasure'
                          let start_buy_event_processor = new StartBuyEventProcessor(this.game, this.player_cards)
                          start_buy_event_processor.process()
                        }
                Severity: Major
                Found in app/game/server/services/card_player.js and 2 other locations - About 1 hr to fix
                app/game/server/services/coffer_player.js on lines 21..25
                app/game/server/services/lib/card_buyer.js on lines 31..35

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

                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

                  update_log() {
                    this.game.log.push(`<strong>${this.player_cards.username}</strong> plays ${CardView.render(this.card)}`)
                  }
                Severity: Major
                Found in app/game/server/services/card_player.js and 2 other locations - About 1 hr to fix
                app/game/server/services/event_buyer.js on lines 68..70
                app/game/server/services/project_buyer.js on lines 71..73

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

                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

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

                        if (_.includes(_.words(this.card.types), 'action') && this.game.turn.actions > 0) {
                          let turn_event_id = TurnEventModel.insert({
                            game_id: this.game._id,
                            player_id: this.player_cards.player_id,
                            username: this.player_cards.username,
                Severity: Minor
                Found in app/game/server/services/card_player.js and 1 other location - About 35 mins to fix
                app/game/server/services/card_player.js on lines 107..123

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

                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 (this.game.turn.phase === 'action' && _.includes(_.words(this.card.types), 'treasure')) {
                        phase = 'treasure'
                        if (_.includes(_.words(this.card.types), 'action') && this.game.turn.actions > 0) {
                          let turn_event_id = TurnEventModel.insert({
                            game_id: this.game._id,
                Severity: Minor
                Found in app/game/server/services/card_player.js and 2 other locations - About 35 mins to fix
                app/game/server/services/card_player.js on lines 105..145
                app/game/server/services/card_player.js on lines 133..145

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

                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

                      } else if (this.game.turn.phase !== 'night' && _.includes(_.words(this.card.types), 'night')) {
                        if (this.game.turn.phase === 'action') {
                          this.game.turn.phase = 'treasure'
                          let start_buy_event_processor = new StartBuyEventProcessor(this.game, this.player_cards)
                          start_buy_event_processor.process()
                Severity: Minor
                Found in app/game/server/services/card_player.js and 2 other locations - About 35 mins to fix
                app/game/server/services/card_player.js on lines 81..145
                app/game/server/services/card_player.js on lines 105..145

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

                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

                      } else if (this.game.turn.phase === 'action' && _.includes(_.words(this.card.types), 'night')) {
                        phase = 'night'
                        if (_.includes(_.words(this.card.types), 'action') && this.game.turn.actions > 0) {
                          let turn_event_id = TurnEventModel.insert({
                            game_id: this.game._id,
                Severity: Minor
                Found in app/game/server/services/card_player.js and 2 other locations - About 35 mins to fix
                app/game/server/services/card_player.js on lines 81..145
                app/game/server/services/card_player.js on lines 133..145

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

                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