remotestorage/remotestorage-server

View on GitHub
lib/requests.js

Summary

Maintainability
F
4 days
Test Coverage

File requests.js has 330 lines of code (exceeds 250 allowed). Consider refactoring.
Open

var url = require('url'),
  sha1 = require('sha1'),
  async = require('async');

module.exports = function(pathPrefix, scopesInstance, mainInstance) {
Severity: Minor
Found in lib/requests.js - About 3 hrs to fix

    Function doHead has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    module.exports.prototype.doHead = function(req, res, release, username, path, folderContentType) {
      if (path.substr(-1) === '/') {
        this.mainInstance.getRevision(username, path, function(err, revision) {
          if (err) {
            this.error(res, err, req.headers.origin);
    Severity: Minor
    Found in lib/requests.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 handleRequest has 54 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    module.exports.prototype.handleRequest = function(req, res, folderFormat, folderContentType, folder404s) {
      var urlObj = url.parse(req.url, true);
      var path = urlObj.pathname.substring(this.pathPrefix.length);
      var pos = path.indexOf('/');
      var username = path.substring(0, pos);
    Severity: Major
    Found in lib/requests.js - About 2 hrs to fix

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

      module.exports.prototype.doGet = function(req, res, release, username, path, folderFormat, folderContentType) {
        if (path.substr(-1) === '/') {
          this.mainInstance.getRevision(username, path, function(err, revision) {
            if (err) {
              this.error(res, err, req.headers.origin);
      Severity: Minor
      Found in lib/requests.js - About 1 hr to fix

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

        module.exports.prototype.doHead = function(req, res, release, username, path, folderContentType) {
          if (path.substr(-1) === '/') {
            this.mainInstance.getRevision(username, path, function(err, revision) {
              if (err) {
                this.error(res, err, req.headers.origin);
        Severity: Minor
        Found in lib/requests.js - About 1 hr to fix

          Function checkCondMet has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          module.exports.prototype.checkCondMet = function(req, res, username, path, statusCode, cb, release) {
          Severity: Major
          Found in lib/requests.js - About 50 mins to fix

            Function checkFound has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            module.exports.prototype.checkFound = function(req, res, username, path, folder404s, cb, release) {
            Severity: Major
            Found in lib/requests.js - About 50 mins to fix

              Function doGet has 7 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              module.exports.prototype.doGet = function(req, res, release, username, path, folderFormat, folderContentType) {
              Severity: Major
              Found in lib/requests.js - About 50 mins to fix

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

                module.exports.prototype.checkNoFolder = function(req, res, username, path, cb, release) {
                Severity: Minor
                Found in lib/requests.js - About 45 mins to fix

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

                  module.exports.prototype.writeHead = function(res, status, origin, revision, contentType, contentLength) {
                  Severity: Minor
                  Found in lib/requests.js - About 45 mins to fix

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

                    module.exports.prototype.writeRaw = function(res, contentType, content, origin, revision, explicitLength) {
                    Severity: Minor
                    Found in lib/requests.js - About 45 mins to fix

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

                      module.exports.prototype.doHead = function(req, res, release, username, path, folderContentType) {
                      Severity: Minor
                      Found in lib/requests.js - About 45 mins to fix

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

                        module.exports.prototype.checkMayWrite = function(req, res, username, path, cb, release) {
                        Severity: Minor
                        Found in lib/requests.js - About 45 mins to fix

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

                          module.exports.prototype.checkFound = function(req, res, username, path, folder404s, cb, release) {
                            if (path.substr(-1) === '/' && !folder404s) {//folders always exist in new spec versions
                              cb();
                            } else {
                              this.mainInstance.exists(username, path, function(err, answer) {
                          Severity: Minor
                          Found in lib/requests.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 checkMayRead has 6 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                          module.exports.prototype.checkMayRead = function(req, res, username, path, cb, release) {
                          Severity: Minor
                          Found in lib/requests.js - About 45 mins to fix

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

                            module.exports.prototype.doDelete = function(req, res, release, username, path) {
                            Severity: Minor
                            Found in lib/requests.js - About 35 mins to fix

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

                              module.exports.prototype.doPut = function(req, res, release, username, path) {
                              Severity: Minor
                              Found in lib/requests.js - About 35 mins to fix

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

                                module.exports.prototype.handleRequest = function(req, res, folderFormat, folderContentType, folder404s) {
                                Severity: Minor
                                Found in lib/requests.js - About 35 mins to fix

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

                                  module.exports.prototype.stripQuotes = function(str) {
                                    var i, parts, ret = [];
                                    if (typeof(str) !== 'string') {
                                      return undefined;
                                    }
                                  Severity: Minor
                                  Found in lib/requests.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

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

                                  module.exports.prototype.checkMayRead = function(req, res, username, path, cb, release) {
                                    this.scopesInstance.mayRead(req.headers.authorization, username, path, function(err, answer) {
                                      if (err) {
                                        this.error(res, err, req.headers.origin);
                                        //console.log('checkMayRead:err calling release');
                                  Severity: Major
                                  Found in lib/requests.js and 1 other location - About 6 hrs to fix
                                  lib/requests.js on lines 108..122

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

                                  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

                                  module.exports.prototype.checkMayWrite = function(req, res, username, path, cb, release) {
                                    this.scopesInstance.mayWrite(req.headers.authorization, username, path, function(err, answer) {
                                      if (err) {
                                        this.error(res, err, req.headers.origin);
                                        //console.log('checkMayWrite:err calling release');
                                  Severity: Major
                                  Found in lib/requests.js and 1 other location - About 6 hrs to fix
                                  lib/requests.js on lines 93..107

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

                                  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

                                      this.mainInstance.set(username, path, body, contentType, revision, function(err) {
                                        if (err) {
                                          this.error(res, err, req.headers.origin);
                                        } else {
                                          this.writeRaw(res, undefined, undefined, req.headers.origin, revision);
                                  Severity: Major
                                  Found in lib/requests.js and 1 other location - About 1 hr to fix
                                  lib/requests.js on lines 261..269

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

                                  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

                                              this.mainInstance.getContent(username, path, function(err3, content) {
                                                if (err) {
                                                  this.error(res, err, req.headers.origin);
                                                } else {
                                                  this.writeRaw(res, contentType, content, req.headers.origin, revision);
                                  Severity: Major
                                  Found in lib/requests.js and 1 other location - About 1 hr to fix
                                  lib/requests.js on lines 291..299

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

                                  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