linagora/openpaas-esn

View on GitHub
backend/webserver/controllers/avatars.js

Summary

Maintainability
C
1 day
Test Coverage

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

function get(req, res) {
  if (!req.query.objectType) {
    if (!req.query.email || typeof req.query.email !== 'string' || req.query.email.length === 0) {
      return res.status(400).json({ error: { code: 400, message: 'Bad request', details: 'When no objectType is provided, email is mandatory and must be a non-empty string'}});
    }
Severity: Minor
Found in backend/webserver/controllers/avatars.js - About 1 hr to fix

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

    function get(req, res) {
      if (!req.query.objectType) {
        if (!req.query.email || typeof req.query.email !== 'string' || req.query.email.length === 0) {
          return res.status(400).json({ error: { code: 400, message: 'Bad request', details: 'When no objectType is provided, email is mandatory and must be a non-empty string'}});
        }
    Severity: Minor
    Found in backend/webserver/controllers/avatars.js - About 55 mins to fix

    Cognitive Complexity

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

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

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

    Further reading

    Avoid too many return statements within this function.
    Open

        return getGeneratedAvatar(req, res);
    Severity: Major
    Found in backend/webserver/controllers/avatars.js - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

        return res.status(400).json({ error: { code: 400, message: 'Bad request', details: 'Unknown objectType parameter'}});
      Severity: Major
      Found in backend/webserver/controllers/avatars.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

            return getAvatar(req, res);
        Severity: Major
        Found in backend/webserver/controllers/avatars.js - About 30 mins to fix

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

            if (!req.query.email || typeof req.query.email !== 'string' || req.query.email.length === 0) {
              return res.status(400).json({ error: { code: 400, message: 'Bad request', details: 'Email is mandatory and must be a non-empty string' } });
            }
          Severity: Major
          Found in backend/webserver/controllers/avatars.js and 1 other location - About 3 hrs to fix
          backend/webserver/controllers/avatars.js on lines 17..19

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

          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

              if (!req.query.email || typeof req.query.email !== 'string' || req.query.email.length === 0) {
                return res.status(400).json({ error: { code: 400, message: 'Bad request', details: 'When no objectType is provided, email is mandatory and must be a non-empty string'}});
              }
          Severity: Major
          Found in backend/webserver/controllers/avatars.js and 1 other location - About 3 hrs to fix
          backend/webserver/controllers/avatars.js on lines 107..109

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

          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 16 locations. Consider refactoring.
          Open

            if (!req.query.id) {
              return res.status(400).json({ error: { code: 400, message: 'Bad request', details: 'Collaboration id is mandatory'}});
            }
          Severity: Major
          Found in backend/webserver/controllers/avatars.js and 15 other locations - About 1 hr to fix
          backend/webserver/controllers/authtoken.js on lines 25..27
          backend/webserver/controllers/avatars.js on lines 82..84
          backend/webserver/controllers/files.js on lines 110..112
          backend/webserver/controllers/files.js on lines 163..165
          backend/webserver/controllers/messages.js on lines 208..210
          backend/webserver/middleware/collaboration.js on lines 17..19
          backend/webserver/middleware/collaboration.js on lines 21..23
          backend/webserver/middleware/collaboration.js on lines 163..165
          backend/webserver/middleware/feedback.js on lines 8..10
          backend/webserver/middleware/feedback.js on lines 12..14
          backend/webserver/middleware/token.js on lines 26..28
          modules/linagora.esn.davproxy/backend/webserver/addressbooks/middleware.js on lines 12..20
          modules/linagora.esn.davproxy/backend/webserver/addressbooks/middleware.js on lines 22..30
          modules/linagora.esn.davproxy/backend/webserver/addressbooks/middleware.js on lines 32..40
          modules/linagora.esn.davproxy/backend/webserver/addressbooks/middleware.js on lines 70..78

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

          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 16 locations. Consider refactoring.
          Open

            if (!req.query.id) {
              return res.status(400).json({ error: { code: 400, message: 'Bad request', details: 'Avatar id is mandatory'}});
            }
          Severity: Major
          Found in backend/webserver/controllers/avatars.js and 15 other locations - About 1 hr to fix
          backend/webserver/controllers/authtoken.js on lines 25..27
          backend/webserver/controllers/avatars.js on lines 65..67
          backend/webserver/controllers/files.js on lines 110..112
          backend/webserver/controllers/files.js on lines 163..165
          backend/webserver/controllers/messages.js on lines 208..210
          backend/webserver/middleware/collaboration.js on lines 17..19
          backend/webserver/middleware/collaboration.js on lines 21..23
          backend/webserver/middleware/collaboration.js on lines 163..165
          backend/webserver/middleware/feedback.js on lines 8..10
          backend/webserver/middleware/feedback.js on lines 12..14
          backend/webserver/middleware/token.js on lines 26..28
          modules/linagora.esn.davproxy/backend/webserver/addressbooks/middleware.js on lines 12..20
          modules/linagora.esn.davproxy/backend/webserver/addressbooks/middleware.js on lines 22..30
          modules/linagora.esn.davproxy/backend/webserver/addressbooks/middleware.js on lines 32..40
          modules/linagora.esn.davproxy/backend/webserver/addressbooks/middleware.js on lines 70..78

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

          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