qcminecraft/Carbon-Forum-F

View on GitHub
static/editor/dialogs/wordimage/tangram.js

Summary

Maintainability
F
6 days
Test Coverage

File tangram.js has 674 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// Copyright (c) 2009, Baidu Inc. All rights reserved.
// 
// Licensed under the BSD License
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Severity: Major
Found in static/editor/dialogs/wordimage/tangram.js - About 1 day to fix

    Function stringify has 103 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    baidu.json.stringify = (function () {
        /**
         * 字符串处理时需要转义的字符表
         * @private
         */
    Severity: Major
    Found in static/editor/dialogs/wordimage/tangram.js - About 4 hrs to fix

      Function createHTML has 99 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      baidu.swf.createHTML = function (options) {
          options = options || {};
          var version = baidu.swf.version, 
              needVersion = options['ver'] || '6.0.0', 
              vUnit1, vUnit2, i, k, len, item, tmpOpt = {},
      Severity: Major
      Found in static/editor/dialogs/wordimage/tangram.js - About 3 hrs to fix

        Function _Base has 94 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        baidu.flash._Base = (function(){
           
            var prefix = 'bd__flash__';
        
            /**
        Severity: Major
        Found in static/editor/dialogs/wordimage/tangram.js - About 3 hrs to fix

          Function createHTML has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
          Open

          baidu.swf.createHTML = function (options) {
              options = options || {};
              var version = baidu.swf.version, 
                  needVersion = options['ver'] || '6.0.0', 
                  vUnit1, vUnit2, i, k, len, item, tmpOpt = {},
          Severity: Minor
          Found in static/editor/dialogs/wordimage/tangram.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 fileUploader has 73 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          baidu.flash.fileUploader = baidu.flash.fileUploader || function(options){
              var me = this,
                  options = options || {};
              
              options.createOptions = baidu.extend({
          Severity: Major
          Found in static/editor/dialogs/wordimage/tangram.js - About 2 hrs to fix

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

            baidu.flash.fileUploader = baidu.flash.fileUploader || function(options){
                var me = this,
                    options = options || {};
                
                options.createOptions = baidu.extend({
            Severity: Minor
            Found in static/editor/dialogs/wordimage/tangram.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 callByServer has 46 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            baidu.sio.callByServer = /**@function*/function(url, callback, opt_options) {
                var scr = document.createElement('SCRIPT'),
                    prefix = 'bd__cbs__',
                    callbackName,
                    callbackImpl,
            Severity: Minor
            Found in static/editor/dialogs/wordimage/tangram.js - About 1 hr to fix

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

              baidu.swf.version = (function () {
                  var n = navigator;
                  if (n.plugins && n.mimeTypes.length) {
                      var plugin = n.plugins["Shockwave Flash"];
                      if (plugin && plugin.description) {
              Severity: Minor
              Found in static/editor/dialogs/wordimage/tangram.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 stringify has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

              baidu.json.stringify = (function () {
                  /**
                   * 字符串处理时需要转义的字符表
                   * @private
                   */
              Severity: Minor
              Found in static/editor/dialogs/wordimage/tangram.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 callByBrowser has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              baidu.sio.callByBrowser = function (url, opt_callback, opt_options) {
                  var scr = document.createElement("SCRIPT"),
                      scriptLoaded = 0,
                      options = opt_options || {},
                      charset = options['charset'],
              Severity: Minor
              Found in static/editor/dialogs/wordimage/tangram.js - About 1 hr to fix

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

                baidu.flash._Base = (function(){
                   
                    var prefix = 'bd__flash__';
                
                    /**
                Severity: Minor
                Found in static/editor/dialogs/wordimage/tangram.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 callByServer has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                baidu.sio.callByServer = /**@function*/function(url, callback, opt_options) {
                    var scr = document.createElement('SCRIPT'),
                        prefix = 'bd__cbs__',
                        callbackName,
                        callbackImpl,
                Severity: Minor
                Found in static/editor/dialogs/wordimage/tangram.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

                Function insertHTML has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                baidu.dom.insertHTML = function (element, position, html) {
                    element = baidu.dom.g(element);
                    var range,begin;
                    if (element.insertAdjacentHTML && !baidu.browser.opera) {
                        element.insertAdjacentHTML(position, html);
                Severity: Minor
                Found in static/editor/dialogs/wordimage/tangram.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

                Function _removeScriptTag has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                baidu.sio._removeScriptTag = function(scr){
                    if (scr.clearAttributes) {
                        scr.clearAttributes();
                    } else {
                        for (var attr in scr) {
                Severity: Minor
                Found in static/editor/dialogs/wordimage/tangram.js - About 45 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

                                        switch (typeof item) {
                                        case 'undefined':
                                        case 'unknown':
                                        case 'function':
                                            break;
                Severity: Major
                Found in static/editor/dialogs/wordimage/tangram.js - About 45 mins to fix

                  Function getMovie has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                  baidu.swf.getMovie = function (name) {
                      var movie = document[name], ret;
                      return baidu.browser.ie == 9 ?
                          movie && movie.length ? 
                              (ret = baidu.array.remove(baidu.lang.toArray(movie),function(item){
                  Severity: Minor
                  Found in static/editor/dialogs/wordimage/tangram.js - About 45 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 toArray has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                  baidu.lang.toArray = function (source) {
                      if (source === null || source === undefined)
                          return [];
                      if (baidu.lang.isArray(source))
                          return source;
                  Severity: Minor
                  Found in static/editor/dialogs/wordimage/tangram.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

                      return [].slice.call(source);
                  Severity: Major
                  Found in static/editor/dialogs/wordimage/tangram.js - About 30 mins to fix

                    Function each has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                    baidu.each = baidu.array.forEach = baidu.array.each = function (source, iterator, thisObject) {
                        var returnValue, item, i, len = source.length;
                        
                        if ('function' == typeof iterator) {
                            for (i = 0; i < len; i++) {
                    Severity: Minor
                    Found in static/editor/dialogs/wordimage/tangram.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

                    Function callByBrowser has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                    baidu.sio.callByBrowser = function (url, opt_callback, opt_options) {
                        var scr = document.createElement("SCRIPT"),
                            scriptLoaded = 0,
                            options = opt_options || {},
                            charset = options['charset'],
                    Severity: Minor
                    Found in static/editor/dialogs/wordimage/tangram.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

                        me.addFileType = function(type){
                            var type = type || [[]];
                            
                            if(type instanceof Array) type = [type];
                            else type = [[type]];
                    Severity: Major
                    Found in static/editor/dialogs/wordimage/tangram.js and 1 other location - About 2 hrs to fix
                    static/editor/dialogs/wordimage/tangram.js on lines 992..998

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

                    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

                        me.setFileType = function(type){
                            var type = type || [[]];
                            
                            if(type instanceof Array) type = [type];
                            else type = [[type]];
                    Severity: Major
                    Found in static/editor/dialogs/wordimage/tangram.js and 1 other location - About 2 hrs to fix
                    static/editor/dialogs/wordimage/tangram.js on lines 978..984

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

                    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

                    baidu.lang.isFunction = function (source) {
                        return '[object Function]' == Object.prototype.toString.call(source);
                    };
                    Severity: Minor
                    Found in static/editor/dialogs/wordimage/tangram.js and 1 other location - About 40 mins to fix
                    static/editor/dialogs/wordimage/tangram.js on lines 512..514

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

                    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

                    baidu.lang.isArray = function (source) {
                        return '[object Array]' == Object.prototype.toString.call(source);
                    };
                    Severity: Minor
                    Found in static/editor/dialogs/wordimage/tangram.js and 1 other location - About 40 mins to fix
                    static/editor/dialogs/wordimage/tangram.js on lines 124..126

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

                    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