engagementgamelab/CivicSeed

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

Summary

Maintainability
F
6 days
Test Coverage

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

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

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

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

    Function addContent has 142 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      addContent: function (section) {
        var overlay = document.getElementById('botanist-area')
        var content = overlay.querySelector('.botanist-content')
    
        // Reset all resource slides and buttons to a hidden & clean state.
    Severity: Major
    Found in client/code/game/game.botanist.js - About 5 hrs to fix

      _botanist has 33 functions (exceeds 20 allowed). Consider refactoring.
      Open

      var _botanist = {
      
        data: {},
        state: null,
        tutorialState: 0,
      Severity: Minor
      Found in client/code/game/game.botanist.js - About 4 hrs to fix

        Function checkPuzzleAnswer has 68 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          checkPuzzleAnswer: function () {
            var allTangrams = $('.puzzle-svg > path')
            var correct = true
            var numRight = 0
            var aLength = $botanist.tangram[$game.$player.currentLevel].answer.length
        Severity: Major
        Found in client/code/game/game.botanist.js - About 2 hrs to fix

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

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

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

              checkState: function () {
                // Prevent check from occurring if Botanist state is not at 2 or 3
                // (resource collecting mode)
                if ($botanist.getState() < 2) return false
            
            
            Severity: Minor
            Found in client/code/game/game.botanist.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 doTutorial has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              doTutorial: function () {
                var tutorialState = _botanist.tutorialState
                var dialogue = ''
            
                switch (tutorialState) {
            Severity: Minor
            Found in client/code/game/game.botanist.js - About 1 hr to fix

              Function show has 37 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                show: function () {
                  var level = $game.$player.currentLevel
              
                  // Clear nudges if present
                  clearInterval(_botanist.nudgePlayerInterval)
              Severity: Minor
              Found in client/code/game/game.botanist.js - About 1 hr to fix

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

                  onTangramDrop: function (e) {
                    e.preventDefault()
                    e.stopPropagation()
                
                    // Fetch tangram data from the data passed through the event data transfer
                Severity: Minor
                Found in client/code/game/game.botanist.js - About 1 hr to fix

                  Function checkState has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    checkState: function () {
                      // Prevent check from occurring if Botanist state is not at 2 or 3
                      // (resource collecting mode)
                      if ($botanist.getState() < 2) return false
                  
                  
                  Severity: Minor
                  Found in client/code/game/game.botanist.js - About 1 hr to fix

                    Function onTangramDrag has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      onTangramDrag: function (d) {
                        var x = d3.event.sourceEvent.layerX
                        var y = d3.event.sourceEvent.layerY
                    //        mX       = d3.event.x
                    //        mY       = d3.event.y
                    Severity: Minor
                    Found in client/code/game/game.botanist.js - About 1 hr to fix

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

                        idle: function () {
                          _counter += 1
                      
                          if (_botanist.renderInfo.srcY === 0) {
                            if (_counter >= 24) {
                      Severity: Minor
                      Found in client/code/game/game.botanist.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

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

                        doTutorial: function () {
                          var tutorialState = _botanist.tutorialState
                          var dialogue = ''
                      
                          switch (tutorialState) {
                      Severity: Minor
                      Found in client/code/game/game.botanist.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

                      Avoid too many return statements within this function.
                      Open

                            if (!found) return false
                      Severity: Major
                      Found in client/code/game/game.botanist.js - About 30 mins to fix

                        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.botanist.js and 1 other location - About 2 hrs to fix
                        client/code/game/game.resources.js on lines 304..308

                        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 (!found) {
                                wrongOne = true
                                correct = false
                                // remove it from the board
                                $('.br' + tanId).remove()
                        Severity: Major
                        Found in client/code/game/game.botanist.js and 1 other location - About 1 hr to fix
                        client/code/game/game.botanist.js on lines 1089..1097

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

                        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

                              } else if (found && !correctPiece) {
                                nudge = true
                                correct = false
                                // remove it from the board
                                $('.br' + tanId).remove()
                        Severity: Major
                        Found in client/code/game/game.botanist.js and 1 other location - About 1 hr to fix
                        client/code/game/game.botanist.js on lines 1081..1097

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

                        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.botanist.js and 1 other location - About 1 hr to fix
                        client/code/game/game.resources.js on lines 365..368

                        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

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

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

                        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()
                                    _botanist.addContent(section)
                        Severity: Major
                        Found in client/code/game/game.botanist.js and 1 other location - About 1 hr to fix
                        client/code/game/game.botanist.js on lines 686..692

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

                        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 'save':
                                  save.style.display = 'inline-block'
                                  save.addEventListener('click', function () {
                                    if (typeof callback === 'function') callback()
                                  })
                        Severity: Minor
                        Found in client/code/game/game.botanist.js and 1 other location - About 45 mins to fix
                        client/code/game/game.botanist.js on lines 708..713

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

                        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 'answer':
                                  answer.style.display = 'inline-block'
                                  answer.addEventListener('click', function () {
                                    if (typeof callback === 'function') callback()
                                  })
                        Severity: Minor
                        Found in client/code/game/game.botanist.js and 1 other location - About 45 mins to fix
                        client/code/game/game.botanist.js on lines 715..720

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

                        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 (x > trash.left && x < trash.right && y > trash.top && y < trash.bottom) {
                              $('.br' + d.id).remove()
                              $('.r' + d.id)
                                .css('opacity', 1)
                                .attr('draggable', 'true')
                        Severity: Minor
                        Found in client/code/game/game.botanist.js and 1 other location - About 35 mins to fix
                        client/code/game/game.botanist.js on lines 993..999

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

                        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 (x > trash.left && x < trash.right && y > trash.top && y < trash.bottom) {
                              trashEl.classList.add('active')
                              trashing = true
                            } else {
                              trashEl.classList.remove('active')
                        Severity: Minor
                        Found in client/code/game/game.botanist.js and 1 other location - About 35 mins to fix
                        client/code/game/game.botanist.js on lines 1024..1030

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

                        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