engagementgamelab/CivicSeed

View on GitHub
client/code/game/game.resources.js

Summary

Maintainability
F
1 wk
Test Coverage

File game.resources.js has 749 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict'
/* global ss, $, $game, d3 */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Severity: Major
Found in client/code/game/game.resources.js - About 1 day to fix

    Function addContent has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring.
    Open

      addContent: function (resourceId, section, slide) {
        var overlay = document.getElementById('resource-area')
        var answer = $game.$player.getAnswer(resourceId)
        var isAnswered = (answer && answer.result) ? true : false
        var isRevisit = $game.flags.check('viewing-inventory')
    Severity: Minor
    Found in client/code/game/game.resources.js - 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 addContent has 174 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      addContent: function (resourceId, section, slide) {
        var overlay = document.getElementById('resource-area')
        var answer = $game.$player.getAnswer(resourceId)
        var isAnswered = (answer && answer.result) ? true : false
        var isRevisit = $game.flags.check('viewing-inventory')
    Severity: Major
    Found in client/code/game/game.resources.js - About 6 hrs to fix

      Function makeResumeFormHTML has 114 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        makeResumeFormHTML: function (resource) {
          var html = ''
      
          // Notes on questions and desired functionality from Sam's Google Doc
          switch (resource.answer) {
      Severity: Major
      Found in client/code/game/game.resources.js - About 4 hrs to fix

        Function _addButton has 75 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            function _addButton (button, section, slide, callback) {
              var buttons = overlay.querySelector('.buttons')
              var back = buttons.querySelector('.back-button')
              var next = buttons.querySelector('.next-button')
              var answer = buttons.querySelector('.answer-button')
        Severity: Major
        Found in client/code/game/game.resources.js - About 3 hrs to fix

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

          var _resources = {
          
            data: [],
            temporaryAnswer: '',
          
          
          Severity: Minor
          Found in client/code/game/game.resources.js - About 2 hrs to fix

            Function loadQuestion has 46 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              loadQuestion: function (resource) {
                var overlay = document.getElementById('resource-area')
                var el = overlay.querySelector('.resource-question')
                var form = el.querySelector('form')
                var formHTML = ''
            Severity: Minor
            Found in client/code/game/game.resources.js - About 1 hr to fix

              Function loadResponses has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                loadResponses: function (resource) {
                  var el = document.getElementById('resource-area').querySelector('.resource-responses')
                  var playerResource = $game.$player.getAnswer(resource.id)
                  var playerPublic = false
                  var playerHTML = ''
              Severity: Minor
              Found in client/code/game/game.resources.js - About 1 hr to fix

                Function loadRewards has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  loadRewards: function (resource) {
                    var el = document.getElementById('resource-area').querySelector('.resource-content')
                    var input = el.querySelector('.tagline-input input')
                    var npc = $game.$npc.findNpcByResourceId(resource.id)
                    var playerLevel = $game.$player.currentLevel
                Severity: Minor
                Found in client/code/game/game.resources.js - About 1 hr to fix

                  Function init has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    init: function (callback) {
                      // Get all resources
                      var npcs = $game.$npc.getNpcData()
                  
                      $.each(npcs, function (key, npc) {
                  Severity: Minor
                  Found in client/code/game/game.resources.js - About 1 hr to fix

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

                      loadResponses: function (resource) {
                        var el = document.getElementById('resource-area').querySelector('.resource-responses')
                        var playerResource = $game.$player.getAnswer(resource.id)
                        var playerPublic = false
                        var playerHTML = ''
                    Severity: Minor
                    Found in client/code/game/game.resources.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 init has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                      init: function (callback) {
                        // Get all resources
                        var npcs = $game.$npc.getNpcData()
                    
                        $.each(npcs, function (key, npc) {
                    Severity: Minor
                    Found in client/code/game/game.resources.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

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

                        _.each(buttons.querySelectorAll('button'), function (button) {
                          var clone = button.cloneNode(true)
                          button = button.parentNode.replaceChild(clone, button)
                          clone.style.display = 'none'
                        })
                    Severity: Major
                    Found in client/code/game/game.resources.js and 1 other location - About 2 hrs to fix
                    client/code/game/game.botanist.js on lines 761..765

                    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

                            case 'back':
                              back.style.display = 'inline-block'
                              back.addEventListener('click', function () {
                                if (typeof callback === 'function') callback()
                                _resources.addContent(resourceId, section, slide)
                    Severity: Major
                    Found in client/code/game/game.resources.js and 1 other location - About 1 hr to fix
                    client/code/game/game.resources.js on lines 891..897

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

                    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

                            case 'next':
                              next.style.display = 'inline-block'
                              next.addEventListener('click', function () {
                                if (typeof callback === 'function') callback()
                                _resources.addContent(resourceId, section, slide)
                    Severity: Major
                    Found in client/code/game/game.resources.js and 1 other location - About 1 hr to fix
                    client/code/game/game.resources.js on lines 898..904

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

                    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

                        $('#resource-area .close-overlay').on('click.onCloseResource', function (e) {
                          e.stopImmediatePropagation()
                          e.preventDefault()
                          // Basically, do the same thing as the close button in this case.
                          $('#resource-area .close-button').trigger('click')
                    Severity: Major
                    Found in client/code/game/game.resources.js and 1 other location - About 1 hr to fix
                    client/code/game/game.resources.js on lines 626..631

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

                    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

                        function _getCentroid (selection) {
                          var bbox = selection.node().getBBox()
                          return [bbox.x + bbox.width / 2, bbox.y + bbox.height / 2]
                        }
                    Severity: Major
                    Found in client/code/game/game.resources.js and 1 other location - About 1 hr to fix
                    client/code/game/game.botanist.js on lines 972..975

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

                    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

                          $('#resource-area .close-overlay').on('click.onCloseCheck', function (e) {
                            e.stopImmediatePropagation()
                            e.preventDefault()
                            // Basically, do the same thing as the save button in this case.
                            $('#resource-area .save-button').trigger('click')
                    Severity: Major
                    Found in client/code/game/game.resources.js and 1 other location - About 1 hr to fix
                    client/code/game/game.resources.js on lines 707..712

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

                    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 (!($game.$player.checkForCompletedResource(4001) === true ||
                              $game.$player.checkForCompletedResource(4002) === true ||
                              $game.$player.checkForCompletedResource(4003) === true)) {
                    Severity: Major
                    Found in client/code/game/game.resources.js and 1 other location - About 1 hr to fix
                    client/code/game/game.npc.js on lines 318..320

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

                    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