fossasia/loklak_webclient

View on GitHub
iframely/lib/utils.js

Summary

Maintainability
F
6 days
Test Coverage

File utils.js has 590 lines of code (exceeds 250 allowed). Consider refactoring.
Open

var events = require('events');
var request = require('request');
var zlib = require('zlib');
var iconv = require('iconv-lite');
var async = require('async');
Severity: Major
Found in iframely/lib/utils.js - About 1 day to fix

    Consider simplifying this complex logical expression.
    Open

        if (meta) {
            var isJetpack = meta.twitter && meta.twitter.card === 'jetpack';
            var isWordpress = meta.generator && /wordpress/i.test(meta.generator);
    
            var isShopify = false;
    Severity: Critical
    Found in iframely/lib/utils.js - About 5 hrs to fix

      Function getWhitelistLogData has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

      function getWhitelistLogData(meta, oembed) {
      
          var r = {};
      
          if (meta) {
      Severity: Minor
      Found in iframely/lib/utils.js - About 4 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 filterLinks has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
      Open

      exports.filterLinks = function(data, options) {
      
          var links = data.links;
      
          for(var i = 0; i < links.length;) {
      Severity: Minor
      Found in iframely/lib/utils.js - About 4 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 getImageMetadata has 94 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      exports.getImageMetadata = function(uri, options, callback){
      
          if (typeof options === 'function') {
              callback = options;
              options = {};
      Severity: Major
      Found in iframely/lib/utils.js - About 3 hrs to fix

        Function getWhitelistLogData has 61 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function getWhitelistLogData(meta, oembed) {
        
            var r = {};
        
            if (meta) {
        Severity: Major
        Found in iframely/lib/utils.js - About 2 hrs to fix

          Function getContentType has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

          exports.getContentType = function(uriForCache, uriOriginal, options, cb) {
          
              cache.withCache("content-type:" + uriForCache, function(cb) {
          
                  var timeout, requestInstance, totalTime;
          Severity: Minor
          Found in iframely/lib/utils.js - About 2 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 getUrl has 50 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          var getUrl = exports.getUrl = function(url, options) {
          
              var req = new events.EventEmitter();
          
              var options = options || {};
          Severity: Minor
          Found in iframely/lib/utils.js - About 2 hrs to fix

            Function sendLogToWhitelist has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

            exports.sendLogToWhitelist = function(uri, meta, oembed, whitelistRecord) {
            
                if (!CONFIG.WHITELIST_LOG_URL) {
                    return
                }
            Severity: Minor
            Found in iframely/lib/utils.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 getContentType has 47 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            exports.getContentType = function(uriForCache, uriOriginal, options, cb) {
            
                cache.withCache("content-type:" + uriForCache, function(cb) {
            
                    var timeout, requestInstance, totalTime;
            Severity: Minor
            Found in iframely/lib/utils.js - About 1 hr to fix

              Function isYoutube has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

              function isYoutube(meta) {
              
                  var video;
                  if (meta.og && (video = meta.og.video)) {
                      if (!(video instanceof Array)) {
              Severity: Minor
              Found in iframely/lib/utils.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 filterLinks has 39 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              exports.filterLinks = function(data, options) {
              
                  var links = data.links;
              
                  for(var i = 0; i < links.length;) {
              Severity: Minor
              Found in iframely/lib/utils.js - About 1 hr to fix

                Function generateLinksHtml has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                exports.generateLinksHtml = function(data, options) {
                
                    // Links may be grouped.
                
                    var links = data.links;
                Severity: Minor
                Found in iframely/lib/utils.js - About 1 hr to fix

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

                  exports.getUriStatus = function(uri, options, callback) {
                  
                      if (typeof options === 'function') {
                          callback = options;
                          options = {};
                  Severity: Minor
                  Found in iframely/lib/utils.js - About 1 hr to fix

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

                    exports.sendLogToWhitelist = function(uri, meta, oembed, whitelistRecord) {
                    
                        if (!CONFIG.WHITELIST_LOG_URL) {
                            return
                        }
                    Severity: Minor
                    Found in iframely/lib/utils.js - About 1 hr to fix

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

                      var getHead = function(url, options) {
                      
                          var req = new events.EventEmitter();
                      
                          var options = options || {};
                      Severity: Minor
                      Found in iframely/lib/utils.js - About 1 hr to fix

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

                        var prepareRequestOptions = exports.prepareRequestOptions = function(request_options) {
                        
                            if (CONFIG.PROXY) {
                        
                                var url = request_options.uri || request_options.url;
                        Severity: Minor
                        Found in iframely/lib/utils.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 finish has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                                function finish(error, data) {
                        
                                    if (timeout) {
                                        clearTimeout(timeout);
                                        timeout = null;
                        Severity: Minor
                        Found in iframely/lib/utils.js - About 1 hr to fix

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

                          exports.generateLinksHtml = function(data, options) {
                          
                              // Links may be grouped.
                          
                              var links = data.links;
                          Severity: Minor
                          Found in iframely/lib/utils.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 unifyDate has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                          Open

                          exports.unifyDate = function(date) {
                          
                              if (typeof date === "string" && date.match(/^\d+$/)) {
                                  date = parseInt(date);
                              }
                          Severity: Minor
                          Found in iframely/lib/utils.js - About 55 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 deeply nested control flow statements.
                          Open

                                              if (oembedLink.href.indexOf(SHOPIFY_OEMBED_URLS[i]) > -1) {
                                                  isShopify = true;
                                              }
                          Severity: Major
                          Found in iframely/lib/utils.js - About 45 mins to fix

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

                            function iterateLinks(links, func) {
                            
                                if (links instanceof Array) {
                            
                                    return links.forEach(func);
                            Severity: Minor
                            Found in iframely/lib/utils.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 lowerCaseKeys has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                            var lowerCaseKeys = exports.lowerCaseKeys = function(obj) {
                                for (var k in obj) {
                                    var lowerCaseKey = k.toLowerCase();
                                    if (lowerCaseKey != k) {
                                        obj[lowerCaseKey] = obj[k];
                            Severity: Minor
                            Found in iframely/lib/utils.js - About 25 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

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

                                        (meta.twitter && meta.twitter.card === 'photo')
                                        &&
                                        (meta.og && meta.og.type !== "article")
                                        &&
                                        !isJetpack
                            Severity: Minor
                            Found in iframely/lib/utils.js and 1 other location - About 35 mins to fix
                            iframely/plugins/domains/kickstarter.com.js on lines 42..42

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 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