jcbantuelle/dominion-meteor

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

Summary

Maintainability
F
4 days
Test Coverage

Function find_buy_events has 80 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  find_buy_events() {
    this.buy_events = []
    if (_.includes(BuyEventProcessor.event_cards(), this.buyer.card.name)) {
      if (this.buyer.card.name === 'Messenger') {
        if (_.size(this.buyer.game.turn.bought_things) === 1) {
Severity: Major
Found in app/game/server/services/buy_event_processor.js - About 3 hrs to fix

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

      find_buy_events() {
        this.buy_events = []
        if (_.includes(BuyEventProcessor.event_cards(), this.buyer.card.name)) {
          if (this.buyer.card.name === 'Messenger') {
            if (_.size(this.buyer.game.turn.bought_things) === 1) {
    Severity: Minor
    Found in app/game/server/services/buy_event_processor.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 buy_event has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      static buy_event(game, player_cards, selected_cards, buy_event_processor) {
        if (!_.isEmpty(selected_cards)) {
          let card = selected_cards[0]
          if (card.name === 'Trash Token') {
            if (_.size(player_cards.hand) > 0) {
    Severity: Minor
    Found in app/game/server/services/buy_event_processor.js - About 1 hr to fix

      Function buy_event has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        static buy_event(game, player_cards, selected_cards, buy_event_processor) {
          if (!_.isEmpty(selected_cards)) {
            let card = selected_cards[0]
            if (card.name === 'Trash Token') {
              if (_.size(player_cards.hand) > 0) {
      Severity: Minor
      Found in app/game/server/services/buy_event_processor.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 process has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        process() {
          if (!_.isEmpty(this.buy_events)) {
            let mandatory_buy_events = _.filter(this.buy_events, (event) => {
              return _.includes(BuyEventProcessor.event_cards().concat(BuyEventProcessor.in_play_event_cards()).concat(BuyEventProcessor.overpay_cards()).concat(BuyEventProcessor.duration_attack_cards()).concat(BuyEventProcessor.landmark_cards()).concat(['Embargo', 'Charm', 'Tax']), event.name)
            })
      Severity: Minor
      Found in app/game/server/services/buy_event_processor.js - About 1 hr to fix

        Function process has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          process() {
            if (!_.isEmpty(this.buy_events)) {
              let mandatory_buy_events = _.filter(this.buy_events, (event) => {
                return _.includes(BuyEventProcessor.event_cards().concat(BuyEventProcessor.in_play_event_cards()).concat(BuyEventProcessor.overpay_cards()).concat(BuyEventProcessor.duration_attack_cards()).concat(BuyEventProcessor.landmark_cards()).concat(['Embargo', 'Charm', 'Tax']), event.name)
              })
        Severity: Minor
        Found in app/game/server/services/buy_event_processor.js - 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

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

              if (_.size(this.buy_events) === 1 && !_.isEmpty(mandatory_buy_events)) {
                BuyEventProcessor.buy_event(this.buyer.game, this.buyer.player_cards, this.buy_events, this)
              } else {
                GameModel.update(this.buyer.game._id, this.buyer.game)
                let instructions = `Choose Buy Event To Resolve for ${CardView.render(this.buyer.card)}`
        Severity: Major
        Found in app/game/server/services/buy_event_processor.js and 1 other location - About 1 day to fix
        app/game/server/services/play_card_event_processor.js on lines 43..66

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

        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

            _.times(this.buyer.game.turn.charms, () => {
              let charm = ClassCreator.create('Charm').to_h()
              charm.id = this.generate_event_id()
              this.buy_events.push(charm)
            })
        Severity: Major
        Found in app/game/server/services/buy_event_processor.js and 1 other location - About 2 hrs to fix
        app/game/server/services/gain_event_processor.js on lines 306..310

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

        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 (this.buyer.game_card.embargos > 0) {
              let embargo = ClassCreator.create('Embargo').to_h()
              embargo.id = this.generate_event_id()
              this.buy_events.push(embargo)
            }
        Severity: Major
        Found in app/game/server/services/buy_event_processor.js and 1 other location - About 2 hrs to fix
        app/game/server/services/buy_event_processor.js on lines 105..109

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

        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 (this.buyer.game_card.debt_tokens > 0) {
              let tax = ClassCreator.create('Tax').to_h()
              tax.id = this.generate_event_id()
              this.buy_events.push(tax)
            }
        Severity: Major
        Found in app/game/server/services/buy_event_processor.js and 1 other location - About 2 hrs to fix
        app/game/server/services/buy_event_processor.js on lines 93..97

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

        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

                return _.includes(BuyEventProcessor.event_cards().concat(BuyEventProcessor.in_play_event_cards()).concat(BuyEventProcessor.overpay_cards()).concat(BuyEventProcessor.duration_attack_cards()).concat(BuyEventProcessor.landmark_cards()).concat(['Embargo', 'Charm', 'Tax']), event.name)
        Severity: Major
        Found in app/game/server/services/buy_event_processor.js and 1 other location - About 1 hr to fix
        app/game/server/services/gain_event_processor.js on lines 338..338

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

        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

            _.each(this.buyer.player_cards.duration_attacks, (card) => {
              if (_.includes(BuyEventProcessor.duration_attack_cards(), card.name)) {
                this.buy_events.push(card)
              }
            })
        Severity: Major
        Found in app/game/server/services/buy_event_processor.js and 2 other locations - About 1 hr to fix
        app/game/server/services/trash_event_processor.js on lines 32..36
        app/game/server/services/trash_event_processor.js on lines 38..42

        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 2 locations. Consider refactoring.
        Open

              if (_.includes(BuyEventProcessor.reaction_cards(), card.name)) {
                if (card.name === 'Hovel') {
                  if (_.includes(_.words(this.buyer.card.types), 'victory')) {
                    this.buy_events.push(card)
                  }
        Severity: Major
        Found in app/game/server/services/buy_event_processor.js and 1 other location - About 1 hr to fix
        app/game/server/services/gain_event_processor.js on lines 252..258

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

        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 (_.includes(BuyEventProcessor.reaction_cards(), card.name)) {
                  card_object.buy_reaction(game, player_cards, buy_event_processor.buyer, card)
                } else {
                  card_object.buy_event(buy_event_processor.buyer, card)
                }
        Severity: Major
        Found in app/game/server/services/buy_event_processor.js and 1 other location - About 1 hr to fix
        app/game/server/services/trash_event_processor.js on lines 102..106

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

        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 (trashing_token && trashing_token.card.stack_name === this.buyer.card.stack_name) {
              this.buy_events.push({
                name: 'Trash Token',
                id: this.generate_event_id(),
                trashing_token: true,
        Severity: Minor
        Found in app/game/server/services/buy_event_processor.js and 1 other location - About 50 mins to fix
        app/game/server/services/gain_event_processor.js on lines 323..331

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

        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