oglimmer/citybuilder

View on GitHub
client/game/Card.js

Summary

Maintainability
F
6 days
Test Coverage

Function drawText has a Cognitive Complexity of 56 (exceeds 5 allowed). Consider refactoring.
Open

BaseCard.drawText = function(ctx,text,profitConfig,x,y,width) {
    if(typeof(profitConfig) !== 'undefined') {
        for(var i = 0 ; i < profitConfig.length ; i++) {
            var pf = profitConfig[i];
            if(text.length > 0 ) {
Severity: Minor
Found in client/game/Card.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 Card has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

function Card(id,title,text,actionBit,playType,profitConfig,range,localLevelMod,type,ctx) {
    this.Inherits(BaseCard);
    this.id = id;
    this.title = title;
    this.text = text;
Severity: Minor
Found in client/game/Card.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 Card has 82 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function Card(id,title,text,actionBit,playType,profitConfig,range,localLevelMod,type,ctx) {
    this.Inherits(BaseCard);
    this.id = id;
    this.title = title;
    this.text = text;
Severity: Major
Found in client/game/Card.js - About 3 hrs to fix

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

    BaseCard.drawText = function(ctx,text,profitConfig,x,y,width) {
        if(typeof(profitConfig) !== 'undefined') {
            for(var i = 0 ; i < profitConfig.length ; i++) {
                var pf = profitConfig[i];
                if(text.length > 0 ) {
    Severity: Major
    Found in client/game/Card.js - About 3 hrs to fix

      Function AuctionCard has 44 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function AuctionCard(id,title,text,x,y,profitConfig,range,localLevelMod,type,ctx) {
          this.Inherits(BaseCard);
          this.id = id;
          this.title = title;
          this.text = text;
      Severity: Minor
      Found in client/game/Card.js - About 1 hr to fix

        Function Card has 10 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        function Card(id,title,text,actionBit,playType,profitConfig,range,localLevelMod,type,ctx) {
        Severity: Major
        Found in client/game/Card.js - About 1 hr to fix

          Function AuctionCard has 10 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          function AuctionCard(id,title,text,x,y,profitConfig,range,localLevelMod,type,ctx) {
          Severity: Major
          Found in client/game/Card.js - About 1 hr to fix

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

                this.draw = function(ctx) {  
                    ctx.font = '12px Arial';
                    ctx.beginPath();
                    ctx.rect(this.x,this.y,this.width,this.height);
                    if(this.clicked) {
            Severity: Minor
            Found in client/game/Card.js - About 1 hr to fix

              Function draw has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  this.draw = function(ctx) {  
                      ctx.font = '12px Arial';    
                      ctx.beginPath();
                      ctx.rect(this.x,this.y,this.width,this.height);
                      if(this.clicked) {
              Severity: Minor
              Found in client/game/Card.js - About 1 hr to fix

                Function AuctionCard has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                function AuctionCard(id,title,text,x,y,profitConfig,range,localLevelMod,type,ctx) {
                    this.Inherits(BaseCard);
                    this.id = id;
                    this.title = title;
                    this.text = text;
                Severity: Minor
                Found in client/game/Card.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

                Avoid deeply nested control flow statements.
                Open

                                    for(var j = pf.ht[0] ; j <= pf.ht[1] ; j++) {
                                        if(j!==pf.ht[0]) {
                                            text += " / ";
                                        }
                                        text += UIServices.getHouseTypeText(j);
                Severity: Major
                Found in client/game/Card.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                      for(var k = start ; k <= end ; k++) {
                                          if(k!==start) {
                                              tempTxtDisp += " / ";
                                          }
                                          tempTxtDisp += UIServices.getHouseTypeText(k);
                  Severity: Major
                  Found in client/game/Card.js - About 45 mins to fix

                    Function drawText has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                    BaseCard.drawText = function(ctx,text,profitConfig,x,y,width) {
                    Severity: Minor
                    Found in client/game/Card.js - About 45 mins to fix

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

                                  if(typeof(this.localLevelMod) !== 'undefined' && this.localLevelMod != 0) {
                                      var t = "S:"+this.localLevelMod;
                                      ctx.fillText(t, this.x+this.width-ctx.measureText(t).width-4, this.y+this.height-5);
                                  }        
                      Severity: Major
                      Found in client/game/Card.js and 1 other location - About 3 hrs to fix
                      client/game/Card.js on lines 244..247

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

                      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(typeof(this.localLevelMod) !== 'undefined' && this.localLevelMod != 0) {
                                  var t = "S:"+this.localLevelMod;
                                  ctx.fillText(t, this.x+this.width-ctx.measureText(t).width-4, this.y+this.height-5);
                              }        
                      Severity: Major
                      Found in client/game/Card.js and 1 other location - About 3 hrs to fix
                      client/game/Card.js on lines 191..194

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

                      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

                      BaseCard.prototype.atPos = function(x, y) {   
                          if(x>=this.x && y>=this.y && x<=this.x+this.width && y <=this.y+this.height) {
                              return true;
                          }
                          return false;
                      Severity: Major
                      Found in client/game/Card.js and 1 other location - About 2 hrs to fix
                      client/game/UIElement.js on lines 92..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 94.

                      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(typeof(this.type) !== 'undefined') {
                                  ctx.fillText(UIServices.getFieldType(this.type), this.x+this.width-ctx.measureText(this.type).width-4, this.y+12);
                              }
                      Severity: Major
                      Found in client/game/Card.js and 1 other location - About 2 hrs to fix
                      client/game/Card.js on lines 182..184

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

                      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(typeof(this.type) !== 'undefined') {
                                  ctx.fillText(UIServices.getFieldType(this.type), this.x+this.width-ctx.measureText(this.type).width-4, this.y+12);
                              }
                      Severity: Major
                      Found in client/game/Card.js and 1 other location - About 2 hrs to fix
                      client/game/Card.js on lines 237..239

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

                      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

                      BaseCard.prototype.Inherits = function(parent) {
                          if(arguments.length > 1) {
                              parent.apply(this, Array.prototype.slice.call(arguments, 1) );
                          } else {      
                              parent.call(this);
                      Severity: Major
                      Found in client/game/Card.js and 1 other location - About 2 hrs to fix
                      client/game/CanvasManager.js on lines 10..16

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

                      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(typeof(this.range) !== 'undefined') {
                                  ctx.fillText("E:"+this.range, this.x+5, this.y+this.height-5);
                              }    
                      Severity: Major
                      Found in client/game/Card.js and 1 other location - About 1 hr to fix
                      client/game/Card.js on lines 188..190

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

                      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(typeof(this.range) !== 'undefined') {
                                      ctx.fillText("E:"+this.range, this.x+5, this.y+this.height-5);
                                  }    
                      Severity: Major
                      Found in client/game/Card.js and 1 other location - About 1 hr to fix
                      client/game/Card.js on lines 241..243

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

                      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

                              ctx.fillText(G.i18n[this.title]/*+" ("+this.id+")"*/, this.x+5, this.y+12);
                      Severity: Minor
                      Found in client/game/Card.js and 1 other location - About 30 mins to fix
                      client/game/Card.js on lines 236..236

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

                      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

                              ctx.fillText(G.i18n[this.title]/*+" ("+this.id+")"*/, this.x+5, this.y+12);
                      Severity: Minor
                      Found in client/game/Card.js and 1 other location - About 30 mins to fix
                      client/game/Card.js on lines 181..181

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

                      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