catarse/catarse.js

View on GitHub
legacy/spec/lib/analytics.js

Summary

Maintainability
F
6 days
Test Coverage

Function CatarseAnalytics has a Cognitive Complexity of 148 (exceeds 5 allowed). Consider refactoring.
Open

window.CatarseAnalytics = window.CatarseAnalytics || (function(){
    /*!
   * cookie-monster - a simple cookie library
   * v0.3.0
   * https://github.com/jgallen23/cookie-monster
Severity: Minor
Found in legacy/spec/lib/analytics.js - About 3 days 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 CatarseAnalytics has 263 lines of code (exceeds 25 allowed). Consider refactoring.
Open

window.CatarseAnalytics = window.CatarseAnalytics || (function(){
    /*!
   * cookie-monster - a simple cookie library
   * v0.3.0
   * https://github.com/jgallen23/cookie-monster
Severity: Major
Found in legacy/spec/lib/analytics.js - About 1 day to fix

    Function _event has 65 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      function _event(eventObj, fn, ignoreGA) {
        if (eventObj) {
          try {
            var project = eventObj.project||_getProject(),
                user = eventObj.user||_getUser();
    Severity: Major
    Found in legacy/spec/lib/analytics.js - About 2 hrs to fix

      File analytics.js has 265 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      //evitamos criar duas vezes...
      //tem q ser não dependente de outros codigos
      window.CatarseAnalytics = window.CatarseAnalytics || (function(){
          /*!
         * cookie-monster - a simple cookie library
      Severity: Minor
      Found in legacy/spec/lib/analytics.js - About 2 hrs to fix

        Consider simplifying this complex logical expression.
        Open

            if (eventObj) {
              try {
                var project = eventObj.project||_getProject(),
                    user = eventObj.user||_getUser();
                var ga = window.ga;//o ga tem q ser verificado aqui pq pode não existir na criaçaõ do DOM
        Severity: Critical
        Found in legacy/spec/lib/analytics.js - About 1 hr to fix

          Function origin has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              var origin = (function(request,cookie) {
                try {
                  var o = JSON.parse(cookie.get('ctrse_origin')||null) || {createdAt: new Date()};
                } catch(e) {
                  o = {createdAt: new Date()};
          Severity: Minor
          Found in legacy/spec/lib/analytics.js - About 1 hr to fix

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

              var ajax = (function(){
                //based on https://raw.githubusercontent.com/yanatan16/nanoajax/v0.2.4/index.js
                function getRequest() {
                  if (window.XMLHttpRequest)
                    return new window.XMLHttpRequest;
            Severity: Minor
            Found in legacy/spec/lib/analytics.js - About 1 hr to fix

              Consider simplifying this complex logical expression.
              Open

                      if(project&&(project.id||project.project_id)) {
                        data.project={
                          id: project.id||project.project_id,
                          user_id: project.user_id||project.project_user_id,
                          category_id: project.category_id,
              Severity: Major
              Found in legacy/spec/lib/analytics.js - About 1 hr to fix

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

                  var monster={set:function(name,value,days,path,secure,domain){var date=new Date(),expires='',type=typeof(value),valueToUse='',secureFlag='';path=path||"/";if(days){date.setTime(date.getTime()+(days*24*60*60*1000));expires="; expires="+date.toUTCString();}if(type==="object"&&type!=="undefined"){if(!("JSON"in window))throw"Bummer, your browser doesn't support JSON parsing.";valueToUse=encodeURIComponent(JSON.stringify({v:value}));}else{valueToUse=encodeURIComponent(value);}if(secure){secureFlag="; secure";}domain=domain?"; domain="+encodeURIComponent(domain):"";document.cookie=name+"="+valueToUse+expires+"; path="+path+secureFlag+domain;},get:function(name){var nameEQ=name+"=",ca=document.cookie.split(';'),value='',firstChar='',parsed={};for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)===0){value=decodeURIComponent(c.substring(nameEQ.length,c.length));firstChar=value.substring(0,1);if(firstChar=="{"){try{parsed=JSON.parse(value);if("v"in parsed)return parsed.v;}catch(e){return value;}}if(value=="undefined")return undefined;return value;}}return null;},remove:function(name){this.set(name,"",-1);},increment:function(name,days){var value=this.get(name)||0;this.set(name,(parseInt(value,10)+1),days);},decrement:function(name,days){var value=this.get(name)||0;this.set(name,(parseInt(value,10)-1),days);}};
                Severity: Minor
                Found in legacy/spec/lib/analytics.js - About 45 mins to fix

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

                    function _checkout(transactionId, prodName, sku, category, price, fee) {
                  Severity: Minor
                  Found in legacy/spec/lib/analytics.js - About 45 mins to fix

                    Consider simplifying this complex logical expression.
                    Open

                          } else if(/*!fromCatarse && */ request.referrer || (!o._time || new Date().getTime()-o._time>10*60*1000/*10min*/)) {
                            var m=request.referrer && request.referrer.match(/https?:\/\/([^\/\?#]+)/);
                            var refDomain=(m && m[1]) || undefined;
                            var query=request.query;
                            //se, e somente se, tem algum utm na query...
                    Severity: Major
                    Found in legacy/spec/lib/analytics.js - About 40 mins to fix

                      Avoid too many return statements within this function.
                      Open

                        var monster={set:function(name,value,days,path,secure,domain){var date=new Date(),expires='',type=typeof(value),valueToUse='',secureFlag='';path=path||"/";if(days){date.setTime(date.getTime()+(days*24*60*60*1000));expires="; expires="+date.toUTCString();}if(type==="object"&&type!=="undefined"){if(!("JSON"in window))throw"Bummer, your browser doesn't support JSON parsing.";valueToUse=encodeURIComponent(JSON.stringify({v:value}));}else{valueToUse=encodeURIComponent(value);}if(secure){secureFlag="; secure";}domain=domain?"; domain="+encodeURIComponent(domain):"";document.cookie=name+"="+valueToUse+expires+"; path="+path+secureFlag+domain;},get:function(name){var nameEQ=name+"=",ca=document.cookie.split(';'),value='',firstChar='',parsed={};for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)===0){value=decodeURIComponent(c.substring(nameEQ.length,c.length));firstChar=value.substring(0,1);if(firstChar=="{"){try{parsed=JSON.parse(value);if("v"in parsed)return parsed.v;}catch(e){return value;}}if(value=="undefined")return undefined;return value;}}return null;},remove:function(name){this.set(name,"",-1);},increment:function(name,days){var value=this.get(name)||0;this.set(name,(parseInt(value,10)+1),days);},decrement:function(name,days){var value=this.get(name)||0;this.set(name,(parseInt(value,10)-1),days);}};
                      Severity: Major
                      Found in legacy/spec/lib/analytics.js - About 30 mins to fix

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

                            if(data) {
                              try {
                                return _user=JSON.parse(data);
                              } catch(e) {
                                console.error('[CatarseAnalytics._getUser] error parsing data '+JSON.stringify(data), e);
                        Severity: Major
                        Found in legacy/spec/lib/analytics.js and 1 other location - About 1 hr to fix
                        legacy/spec/lib/analytics.js on lines 176..182

                        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

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

                            if(data) {
                              try {
                                return  _project=JSON.parse(data);
                              } catch(e) {
                                console.error('[CatarseAnalytics._getProject] error parsing data '+JSON.stringify(data), e);
                        Severity: Major
                        Found in legacy/spec/lib/analytics.js and 1 other location - About 1 hr to fix
                        legacy/spec/lib/analytics.js on lines 163..169

                        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

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

                          var monster={set:function(name,value,days,path,secure,domain){var date=new Date(),expires='',type=typeof(value),valueToUse='',secureFlag='';path=path||"/";if(days){date.setTime(date.getTime()+(days*24*60*60*1000));expires="; expires="+date.toUTCString();}if(type==="object"&&type!=="undefined"){if(!("JSON"in window))throw"Bummer, your browser doesn't support JSON parsing.";valueToUse=encodeURIComponent(JSON.stringify({v:value}));}else{valueToUse=encodeURIComponent(value);}if(secure){secureFlag="; secure";}domain=domain?"; domain="+encodeURIComponent(domain):"";document.cookie=name+"="+valueToUse+expires+"; path="+path+secureFlag+domain;},get:function(name){var nameEQ=name+"=",ca=document.cookie.split(';'),value='',firstChar='',parsed={};for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)===0){value=decodeURIComponent(c.substring(nameEQ.length,c.length));firstChar=value.substring(0,1);if(firstChar=="{"){try{parsed=JSON.parse(value);if("v"in parsed)return parsed.v;}catch(e){return value;}}if(value=="undefined")return undefined;return value;}}return null;},remove:function(name){this.set(name,"",-1);},increment:function(name,days){var value=this.get(name)||0;this.set(name,(parseInt(value,10)+1),days);},decrement:function(name,days){var value=this.get(name)||0;this.set(name,(parseInt(value,10)-1),days);}};
                        Severity: Minor
                        Found in legacy/spec/lib/analytics.js and 1 other location - About 55 mins to fix
                        legacy/spec/lib/analytics.js on lines 11..11

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

                        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