owncloud/core

View on GitHub
apps/files/js/file-upload.js

Summary

Maintainability
F
1 wk
Test Coverage

File file-upload.js has 941 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 * Copyright (c) 2018
 *
 * This file is licensed under the Affero General Public License version 3
 * or later.
Severity: Major
Found in apps/files/js/file-upload.js - About 2 days to fix

    Function init has a Cognitive Complexity of 94 (exceeds 5 allowed). Consider refactoring.
    Open

        init: function($uploadEl, options) {
            var self = this;
            options = options || {};
    
            this._uploads = {};
    Severity: Minor
    Found in apps/files/js/file-upload.js - About 1 day to fix

    Cognitive Complexity

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

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

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

    Further reading

    Function init has 358 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        init: function($uploadEl, options) {
            var self = this;
            options = options || {};
    
            this._uploads = {};
    Severity: Major
    Found in apps/files/js/file-upload.js - About 1 day to fix

      Function add has 86 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

                      add: function(e, data) {
                          self.log('add', e, data);
                          var that = $(this), freeSpace;
      
                          var upload = new OC.FileUpload(self, data);
      Severity: Major
      Found in apps/files/js/file-upload.js - About 3 hrs to fix

        Function fail has 83 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                        fail: function(e, data) {
                            var upload = self.getUpload(data);
                            if (upload && upload.data && upload.data.stalled) {
                                self.log('retry', e, upload);
                                // jQuery Widget Factory uses "namespace-widgetname" since version 1.10.0:
        Severity: Major
        Found in apps/files/js/file-upload.js - About 3 hrs to fix

          Function submit has 63 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              submit: function() {
                  var self = this;
                  var data = this.data;
                  var file = this.getFile();
          
          
          Severity: Major
          Found in apps/files/js/file-upload.js - About 2 hrs to fix

            prototype has 23 functions (exceeds 20 allowed). Consider refactoring.
            Open

            OC.Uploader.prototype = _.extend({
                /**
                 * @type Array<OC.FileUpload>
                 */
                _uploads: {},
            Severity: Minor
            Found in apps/files/js/file-upload.js - About 2 hrs to fix

              prototype has 23 functions (exceeds 20 allowed). Consider refactoring.
              Open

              OC.FileUpload.prototype = {
              
                  /**
                   * Unique upload id
                   *
              Severity: Minor
              Found in apps/files/js/file-upload.js - About 2 hrs to fix

                Function getResponse has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                Open

                    getResponse: function() {
                        var response = this.data.response();
                        if (response.errorThrown) {
                            if (response.errorThrown === 'timeout') {
                                return {
                Severity: Minor
                Found in apps/files/js/file-upload.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 submit has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                Open

                    submit: function() {
                        var self = this;
                        var data = this.data;
                        var file = this.getFile();
                
                
                Severity: Minor
                Found in apps/files/js/file-upload.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 done has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    done: function() {
                        if (!this.data.isChunked) {
                            return $.Deferred().resolve().promise();
                        }
                
                
                Severity: Minor
                Found in apps/files/js/file-upload.js - About 1 hr to fix

                  Function getResponse has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      getResponse: function() {
                          var response = this.data.response();
                          if (response.errorThrown) {
                              if (response.errorThrown === 'timeout') {
                                  return {
                  Severity: Minor
                  Found in apps/files/js/file-upload.js - About 1 hr to fix

                    Function checkExistingFiles has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        checkExistingFiles: function (selection, callbacks) {
                            var self = this;
                            var fileList = this.fileList;
                            var conflicts = [];
                            // only keep non-conflicting uploads
                    Severity: Minor
                    Found in apps/files/js/file-upload.js - About 1 hr to fix

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

                          checkExistingFiles: function (selection, callbacks) {
                              var self = this;
                              var fileList = this.fileList;
                              var conflicts = [];
                              // only keep non-conflicting uploads
                      Severity: Minor
                      Found in apps/files/js/file-upload.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 ensureFolderExists has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          ensureFolderExists: function(fullPath) {
                              if (!fullPath || fullPath === '/') {
                                  return $.Deferred().resolve().promise();
                              }
                      
                      
                      Severity: Minor
                      Found in apps/files/js/file-upload.js - About 1 hr to fix

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

                                selection.uploads = _.filter(selection.uploads, function(upload) {
                                    var file = upload.getFile();
                                    if (file.relativePath) {
                                        // can't check in subfolder contents, let backend handle this
                                        return true;
                        Severity: Minor
                        Found in apps/files/js/file-upload.js - About 1 hr to fix

                          Avoid deeply nested control flow statements.
                          Open

                                                  if (upload) {
                                                      var response = upload.getResponse();
                                                      message = t('files', 'Failed to upload the file "{fileName}": {error}', {fileName: upload.getFileName(), error: response.message});
                                                  }
                          Severity: Major
                          Found in apps/files/js/file-upload.js - About 45 mins to fix

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

                                ensureFolderExists: function(fullPath) {
                                    if (!fullPath || fullPath === '/') {
                                        return $.Deferred().resolve().promise();
                                    }
                            
                            
                            Severity: Minor
                            Found in apps/files/js/file-upload.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 true;
                            Severity: Major
                            Found in apps/files/js/file-upload.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                              return false;
                              Severity: Major
                              Found in apps/files/js/file-upload.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                        return response;
                                Severity: Major
                                Found in apps/files/js/file-upload.js - About 30 mins to fix

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

                                      _updateProgressBar: function() {
                                          var progress = parseInt(this.$uploadprogressbar.attr('data-loaded'), 10);
                                          var total = parseInt(this.$uploadprogressbar.attr('data-total'), 10);
                                          if (progress !== this._lastProgress) {
                                              this._lastProgress = progress;
                                  Severity: Minor
                                  Found in apps/files/js/file-upload.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

                                          this.uploader.davClient.remove(
                                              'uploads/' + OC.getCurrentUser().uid + '/' + this.getId()
                                          );
                                  Severity: Minor
                                  Found in apps/files/js/file-upload.js and 1 other location - About 35 mins to fix
                                  apps/files/js/file-upload.js on lines 317..319

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

                                  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

                                              chunkFolderPromise = this.uploader.davClient.createDirectory(
                                                  'uploads/' + OC.getCurrentUser().uid + '/' + this.getId()
                                              );
                                  Severity: Minor
                                  Found in apps/files/js/file-upload.js and 1 other location - About 35 mins to fix
                                  apps/files/js/file-upload.js on lines 397..399

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

                                  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