CaffGeek/MBACNationals

View on GitHub
Web.Admin/z-scripts/FileAPI.js

Summary

Maintainability
F
2 wks
Test Coverage

File FileAPI.js has 3098 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*! FileAPI 2.0.7 - BSD | git://github.com/mailru/FileAPI.git
 * FileAPI — a set of  javascript tools for working with files. Multiupload, drag'n'drop and chunked file upload. Images: crop, resize and auto orientation by EXIF.
 */

/*
Severity: Major
Found in Web.Admin/z-scripts/FileAPI.js - About 1 wk to fix

    Function patch has 266 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

                    patch: function (){
                        api.flashEngine = true;
    
                        // FileAPI
                        _inherit(api, {
    Severity: Major
    Found in Web.Admin/z-scripts/FileAPI.js - About 1 day to fix

      Function _send has 216 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              _send: function (options, data){
                  var _this = this, xhr, uid = _this.uid, onloadFuncName = _this.uid + "Load", url = options.url;
      
                  api.log('XHR._send:', data);
      
      
      Severity: Major
      Found in Web.Admin/z-scripts/FileAPI.js - About 1 day to fix

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

                    upload: function (options){
                        options = _extend({
                              jsonp: 'callback'
                            , prepare: api.F
                            , beforeupload: api.F
        Severity: Major
        Found in Web.Admin/z-scripts/FileAPI.js - About 5 hrs to fix

          Function _apply has 82 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  _apply: function (image, fn){
                      var
                            canvas = getCanvas()
                          , m = this.getMatrix(image)
                          , ctx = canvas.getContext('2d')
          Severity: Major
          Found in Web.Admin/z-scripts/FileAPI.js - About 3 hrs to fix

            Function renderImageToCanvas has 77 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                loadImage.renderImageToCanvas = function (
                    canvas,
                    img,
                    sourceX,
                    sourceY,
            Severity: Major
            Found in Web.Admin/z-scripts/FileAPI.js - About 3 hrs to fix

              Function _send has 76 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                                      _send: function (options, formData){
                                          if(
                                                 formData.nodeName
                                              || formData.append && api.support.html5
                                              || api.isArray(formData) && (typeof formData[0] === 'string')
              Severity: Major
              Found in Web.Admin/z-scripts/FileAPI.js - About 3 hrs to fix

                Function _getFormData has 66 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                            _getFormData: function (options, data, fn){
                                var
                                      file = data.file
                                    , name = data.name
                                    , filename = file.name
                Severity: Major
                Found in Web.Admin/z-scripts/FileAPI.js - About 2 hrs to fix

                  Function transform has 60 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      Image.transform = function (file, transform, autoOrientation, fn){
                          function _transform(err, img){
                              // img -- info object
                              var
                                    images = {}
                  Severity: Major
                  Found in Web.Admin/z-scripts/FileAPI.js - About 2 hrs to fix

                    Function patchCamera has 56 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                                    patchCamera: function () {
                                        api.Camera.fallback = function (el, options, callback) {
                                            var camId = api.uid();
                                            api.log('FlashAPI.Camera.publish: ' + camId);
                                            flash.publish(el, camId, api.extend(options, {
                    Severity: Major
                    Found in Web.Admin/z-scripts/FileAPI.js - About 2 hrs to fix

                      Function _transform has 53 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                              function _transform(err, img){
                                  // img -- info object
                                  var
                                        images = {}
                                      , queue = api.queue(function (err){
                      Severity: Major
                      Found in Web.Admin/z-scripts/FileAPI.js - About 2 hrs to fix

                        Function onreadystatechange has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                                            xhr.onreadystatechange = function (){
                                                var lkb = parseInt(xhr.getResponseHeader('X-Last-Known-Byte'), 10);
                        
                                                _this.status     = xhr.status;
                                                _this.statusText = xhr.statusText;
                        Severity: Minor
                        Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

                          Function getMatrix has 47 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                                  getMatrix: function (image){
                                      var
                                            m  = api.extend({}, this.matrix)
                                          , sw = m.sw = m.sw || image.videoWidth || image.naturalWidth ||  image.width
                                          , sh = m.sh = m.sh || image.videoHeight || image.naturalHeight || image.height
                          Severity: Minor
                          Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

                            Function readAsImage has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                        readAsImage: function (file, fn, progress){
                                            if( api.isFile(file) ){
                                                if( apiURL ){
                                                    /** @namespace apiURL.createObjectURL */
                                                    var data = apiURL.createObjectURL(file);
                            Severity: Minor
                            Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

                              Function getFiles has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                          getFiles: function (input, filter, callback){
                                              var files = [];
                              
                                              if( callback ){
                                                  api.filterFiles(api.getFiles(input), filter, callback);
                              Severity: Minor
                              Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

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

                                    api.event.dnd = function (el, onHover, onDrop){
                                        var _id, _type;
                                
                                        if( !onDrop ){
                                            onDrop = onHover;
                                Severity: Minor
                                Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

                                  Function publish has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                      Camera.publish = function (el, options, callback){
                                          if( typeof options == 'function' ){
                                              callback = options;
                                              options = {};
                                          }
                                  Severity: Minor
                                  Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

                                    Function _addFile has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                                    (function _addFile(file/**Object*/){
                                                        if( file.image ){ // This is a FileAPI.Image
                                                            queue.inc();
                                    
                                                            file.toData(function (err, image){
                                    Severity: Minor
                                    Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

                                      Function mouseover has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                                      mouseover: function (evt){
                                                          if (!flash.disableMouseover) {
                                                              var target = api.event.fix(evt).target;
                                          
                                                              if( /input/i.test(target.nodeName) && target.type == 'file' && !target.disabled ){
                                      Severity: Minor
                                      Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

                                        Function _apply has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                                        Open

                                                                _apply: function (file, fn){
                                                                    api.log('FlashAPI.Image._apply:', file);
                                        
                                                                    if( _isHtmlFile(file) ){
                                                                        this.parent.apply(this, arguments);
                                        Severity: Minor
                                        Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

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

                                              function _readEntryAsFiles(entry, callback){
                                                  if( !entry ){
                                                      // error
                                                      callback('invalid entry');
                                                  }
                                          Severity: Minor
                                          Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

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

                                                    function _makeFlashImage(opts, base64, fn){
                                                        var
                                                              key
                                                            , flashId = api.uid()
                                                            , el = document.createElement('div')
                                            Severity: Minor
                                            Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

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

                                                  function _convertFile(file, fn, useBinaryString){
                                                      var blob = file.blob, filename = file.file;
                                              
                                                      if( filename ){
                                                          if( !blob.toDataURL ){
                                              Severity: Minor
                                              Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

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

                                                            load: function (url, fn){
                                                                var xhr = api.getXHR();
                                                                if( xhr ){
                                                                    xhr.open('GET', url, true);
                                                
                                                
                                                Severity: Minor
                                                Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

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

                                                              _getFilesDataArray: function (data){
                                                                  var files = [], oFiles = {};
                                                  
                                                                  if( isInputFile(data) ){
                                                                      var tmp = api.getFiles(data);
                                                  Severity: Minor
                                                  Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

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

                                                                getDropFiles: function (evt, callback){
                                                                    var
                                                                          files = []
                                                                        , dataTransfer = _getDataTransfer(evt)
                                                                        , entrySupport = _isArray(dataTransfer.items) && dataTransfer.items[0] && _getAsEntry(dataTransfer.items[0])
                                                    Severity: Minor
                                                    Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

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

                                                          api.renderImageToCanvas = function (canvas, img, sx, sy, sw, sh, dx, dy, dw, dh){
                                                      Severity: Major
                                                      Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

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

                                                                canvas,
                                                                img,
                                                                sourceX,
                                                                sourceY,
                                                                sourceWidth,
                                                        Severity: Major
                                                        Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

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

                                                                      queue: function (fn){
                                                                          var
                                                                                _idx = 0
                                                                              , _length = 0
                                                                              , _fail = false
                                                          Severity: Minor
                                                          Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

                                                            Function toPlainData has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                                            Open

                                                                    toPlainData: function (fn){
                                                                        this._to({}, fn, function (file, data, queue){
                                                                            if( file.file ){
                                                                                data.type = file.file;
                                                                            }
                                                            Severity: Minor
                                                            Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

                                                              Function _readAs has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                                              Open

                                                                  function _readAs(file, fn, as, encoding){
                                                                      if( api.isBlob(file) && _hasSupportReadAs(as) ){
                                                                          var Reader = new FileReader;
                                                              
                                                                          // Add event listener
                                                              Severity: Minor
                                                              Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

                                                                Function queue has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                                                                Open

                                                                                            var queue = api.queue(function (){
                                                                                                flash.uploadInProgress = true;
                                                                                                flash.cmd(flashId, 'upload', {
                                                                                                      url: _getUrl(options.url.replace(/([a-z]+)=(\?)&?/i, ''))
                                                                                                    , data: data
                                                                Severity: Minor
                                                                Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

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

                                                                                  select: function (evt){
                                                                                      try {
                                                                                          var
                                                                                                inp = flash.getInput(evt.flashId)
                                                                                              , uid = api.uid(inp)
                                                                  Severity: Minor
                                                                  Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

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

                                                                                getInfo: function (file, fn){
                                                                                    var info = {}, readers = _infoReader.concat();
                                                                    
                                                                                    if( api.isFile(file) ){
                                                                                        (function _next(){
                                                                    Severity: Minor
                                                                    Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

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

                                                                          loadImage.detectVerticalSquash = function (img, subsampled) {
                                                                              var naturalHeight = img.naturalHeight || img.height,
                                                                                  canvas = document.createElement('canvas'),
                                                                                  context = canvas.getContext('2d'),
                                                                                  data,
                                                                      Severity: Minor
                                                                      Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

                                                                        Function _ has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                                                        Open

                                                                                                            , callback: _wrap(function _(err, base64){
                                                                                                                api.log('FlashAPI.Image._apply.callback:', err);
                                                                                                                _unwrap(_);
                                                                        
                                                                                                                if( err ){
                                                                        Severity: Minor
                                                                        Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

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

                                                                                      window.ArrayBuffer && window.Uint8Array && function (dataURI) {
                                                                                          var byteString,
                                                                                              arrayBuffer,
                                                                                              intArray,
                                                                                              i,
                                                                          Severity: Minor
                                                                          Found in Web.Admin/z-scripts/FileAPI.js - About 1 hr to fix

                                                                            Avoid deeply nested control flow statements.
                                                                            Open

                                                                                                            if (data.end == data.size - 1) {
                                                                                                                // finished
                                                                                                                _this.end(xhr.status);
                                                                                                            } else {
                                                                                                                // next chunk
                                                                            Severity: Major
                                                                            Found in Web.Admin/z-scripts/FileAPI.js - About 45 mins to fix

                                                                              Avoid deeply nested control flow statements.
                                                                              Open

                                                                                                          if( _type != 'dragleave' ){
                                                                                                              onHover.call(evt[currentTarget], true, evt);
                                                                                                          }
                                                                              Severity: Major
                                                                              Found in Web.Admin/z-scripts/FileAPI.js - About 45 mins to fix

                                                                                Avoid deeply nested control flow statements.
                                                                                Open

                                                                                                                if (((!xhr.status && !xhr.aborted) || 500 == xhr.status || 416 == xhr.status) && ++data.retry <= options.chunkUploadRetry) {
                                                                                                                    // let's try again the same chunk
                                                                                                                    // only applicable for recoverable error codes 500 && 416
                                                                                                                    var delay = xhr.status ? 0 : api.chunkNetworkDownRetryTimeout;
                                                                                
                                                                                
                                                                                Severity: Major
                                                                                Found in Web.Admin/z-scripts/FileAPI.js - About 45 mins to fix

                                                                                  Avoid deeply nested control flow statements.
                                                                                  Open

                                                                                                                  if (((!xhr.status && !xhr.aborted) || 500 == xhr.status) && (options.retry || 0) < options.uploadRetry) {
                                                                                                                      options.retry = (options.retry || 0) + 1;
                                                                                                                      var delay = api.networkDownRetryTimeout;
                                                                                  
                                                                                                                      // inform about recoverable problems
                                                                                  Severity: Major
                                                                                  Found in Web.Admin/z-scripts/FileAPI.js - About 45 mins to fix

                                                                                    Avoid deeply nested control flow statements.
                                                                                    Open

                                                                                                                        if( !wrapper ){
                                                                                                                            api.log('[err] FlashAPI.mouseover: js-fileapi-wrapper not found');
                                                                                                                            return;
                                                                                                                        }
                                                                                    Severity: Major
                                                                                    Found in Web.Admin/z-scripts/FileAPI.js - About 45 mins to fix

                                                                                      Consider simplifying this complex logical expression.
                                                                                      Open

                                                                                                          if( ( proxyXHR.statusText != 'abort' || proxyXHR.current ) && data ){
                                                                                                              // Mark active job
                                                                                                              _complete = false;
                                                                                      
                                                                                                              // Set current upload file
                                                                                      Severity: Major
                                                                                      Found in Web.Admin/z-scripts/FileAPI.js - About 40 mins to fix

                                                                                        Consider simplifying this complex logical expression.
                                                                                        Open

                                                                                                                        if (((!xhr.status && !xhr.aborted) || 500 == xhr.status) && (options.retry || 0) < options.uploadRetry) {
                                                                                                                            options.retry = (options.retry || 0) + 1;
                                                                                                                            var delay = api.networkDownRetryTimeout;
                                                                                        
                                                                                                                            // inform about recoverable problems
                                                                                        Severity: Major
                                                                                        Found in Web.Admin/z-scripts/FileAPI.js - About 40 mins to fix

                                                                                          Consider simplifying this complex logical expression.
                                                                                          Open

                                                                                                  if( navigator.plugins && typeof navigator.plugins['Shockwave Flash'] == 'object' ){
                                                                                                      has    = navigator.plugins['Shockwave Flash'].description && !(mime && mime['application/x-shockwave-flash'] && !mime['application/x-shockwave-flash'].enabledPlugin);
                                                                                                  }
                                                                                                  else {
                                                                                                      try {
                                                                                          Severity: Major
                                                                                          Found in Web.Admin/z-scripts/FileAPI.js - About 40 mins to fix

                                                                                            Function _emit has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                                            Open

                                                                                                function _emit(target, fn, name, res, ext){
                                                                                            Severity: Minor
                                                                                            Found in Web.Admin/z-scripts/FileAPI.js - About 35 mins to fix

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

                                                                                                              else {
                                                                                                                  dw = round(sf >= df ? min(sw, dw) : dh*sf);
                                                                                                                  dh = round(sf >= df ? dw/sf : min(sh, dh));
                                                                                                              }
                                                                                              Severity: Major
                                                                                              Found in Web.Admin/z-scripts/FileAPI.js and 1 other location - About 1 hr to fix
                                                                                              Web.Admin/z-scripts/FileAPI.js on lines 2063..2066

                                                                                              Duplicated Code

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

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

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

                                                                                              Tuning

                                                                                              This issue has a mass of 63.

                                                                                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                                              Refactorings

                                                                                              Further Reading

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

                                                                                                              else if( strategy == 'min' ){
                                                                                                                  dw = round(sf < df ? min(sw, dw) : dh*sf);
                                                                                                                  dh = round(sf < df ? dw/sf : min(sh, dh));
                                                                                                              }
                                                                                              Severity: Major
                                                                                              Found in Web.Admin/z-scripts/FileAPI.js and 1 other location - About 1 hr to fix
                                                                                              Web.Admin/z-scripts/FileAPI.js on lines 2067..2070

                                                                                              Duplicated Code

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

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

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

                                                                                              Tuning

                                                                                              This issue has a mass of 63.

                                                                                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                                              Refactorings

                                                                                              Further Reading

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

                                                                                                                  outStr += b64.charAt(enc1) + b64.charAt(enc2) + b64.charAt(enc3) + b64.charAt(enc4);
                                                                                              Severity: Minor
                                                                                              Found in Web.Admin/z-scripts/FileAPI.js and 1 other location - About 35 mins to fix
                                                                                              Web.Admin/z-scripts/ai.0.15.0-build46802.js on lines 1662..1662

                                                                                              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