linagora/openpaas-esn

View on GitHub
backend/webserver/middleware/domain.js

Summary

Maintainability
F
3 days
Test Coverage

File domain.js has 271 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';

const q = require('q');
const emailAddresses = require('email-addresses');
const Domain = require('mongoose').model('Domain');
Severity: Minor
Found in backend/webserver/middleware/domain.js - About 2 hrs to fix

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

    function requireAdministrator(req, res, next) {
      const administrator = req.body.administrator;
      let error, details;
    
      if (!administrator) {
    Severity: Minor
    Found in backend/webserver/middleware/domain.js - About 1 hr to fix

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

      function checkMemberAccounts(req, res, next) {
        const accountList = req.body.accounts;
      
        const errorMessage = {
          error: {
      Severity: Minor
      Found in backend/webserver/middleware/domain.js - About 1 hr to fix

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

        function requireDomainInfo(req, res, next) {
          let details;
        
          if (!req.body.name) {
            details = 'Domain does not have name';
        Severity: Minor
        Found in backend/webserver/middleware/domain.js - About 1 hr to fix

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

          function loadDomainByHostname(req, res, next) {
            const hostname = req.hostname;
          
            coreDomain.getByHostname(hostname)
              .then(domain => {
          Severity: Minor
          Found in backend/webserver/middleware/domain.js - About 1 hr to fix

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

            function checkMemberAccounts(req, res, next) {
              const accountList = req.body.accounts;
            
              const errorMessage = {
                error: {
            Severity: Minor
            Found in backend/webserver/middleware/domain.js - About 45 mins to fix

            Cognitive Complexity

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

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

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

            Further reading

            Avoid too many return statements within this function.
            Open

              return next();
            Severity: Major
            Found in backend/webserver/middleware/domain.js - About 30 mins to fix

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

              function requireDomainInfo(req, res, next) {
                let details;
              
                if (!req.body.name) {
                  details = 'Domain does not have name';
              Severity: Minor
              Found in backend/webserver/middleware/domain.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

                  Domain.loadFromID(domainId, function(err, domain) {
                    if (err) {
                      return next(err);
                    }
              
              
              Severity: Major
              Found in backend/webserver/middleware/domain.js and 1 other location - About 3 hrs to fix
              backend/webserver/middleware/domain.js on lines 78..94

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

              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

                Domain.loadFromID(uuid, function(err, domain) {
                  if (err) {
                    return next(err);
                  }
                  if (!domain) {
              Severity: Major
              Found in backend/webserver/middleware/domain.js and 1 other location - About 3 hrs to fix
              backend/webserver/middleware/domain.js on lines 178..195

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

              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

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

                if (req.body.hostnames) {
                  if (!Array.isArray(req.body.hostnames)) {
                    return res.status(400).json({
                      error: {
                        code: 400,
              Severity: Major
              Found in backend/webserver/middleware/domain.js and 1 other location - About 2 hrs to fix
              backend/webserver/middleware/domain.js on lines 268..280

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

              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

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

                if (req.body.hostnames) {
                  if (!Array.isArray(req.body.hostnames)) {
                    return res.status(400).json({
                      error: {
                        code: 400,
              Severity: Major
              Found in backend/webserver/middleware/domain.js and 1 other location - About 2 hrs to fix
              backend/webserver/middleware/domain.js on lines 137..149

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

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

                q.all(hostnames.map(hostname => coreDomain.getByHostname(hostname)))
                  .then(domains => {
                    const isUsedByOtherDomain = domains.findIndex(domain => domain && String(domain._id) !== req.params.uuid);
              
                    if (isUsedByOtherDomain !== -1) {
              Severity: Major
              Found in backend/webserver/middleware/domain.js and 2 other locations - About 1 hr to fix
              backend/webserver/controllers/css.js on lines 15..30
              backend/webserver/middleware/configuration.js on lines 368..415

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

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

              module.exports = {
                canGetMembers,
                load,
                loadFromDomainIdParameter,
                loadDomainByHostname,
              Severity: Major
              Found in backend/webserver/middleware/domain.js and 2 other locations - About 1 hr to fix
              backend/core/application-discovery-service/index.js on lines 6..16
              backend/webserver/controllers/application-discovery-service.js on lines 4..14

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

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

                if (!dbHelper.isValidObjectId(id)) {
                  return res.status(400).json({ error: { code: 400, message: 'Bad Request', details: 'Invalid domain_id parameter' }});
                }
              Severity: Major
              Found in backend/webserver/middleware/domain.js and 3 other locations - About 1 hr to fix
              backend/webserver/controllers/domains.js on lines 307..311
              backend/webserver/middleware/domain.js on lines 74..76
              backend/webserver/middleware/resource-link.js on lines 44..46

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

                if (!dbHelper.isValidObjectId(uuid)) {
                  return res.status(400).json({ error: { code: 400, message: 'Bad request', details: 'Invalid domain id' }});
                }
              Severity: Major
              Found in backend/webserver/middleware/domain.js and 3 other locations - About 1 hr to fix
              backend/webserver/controllers/domains.js on lines 307..311
              backend/webserver/middleware/domain.js on lines 104..106
              backend/webserver/middleware/resource-link.js on lines 44..46

              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

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

                if (details) {
                  return res.status(400).json({
                    error: {
                      code: 400,
                      message: 'Bad Request',
              Severity: Minor
              Found in backend/webserver/middleware/domain.js and 1 other location - About 30 mins to fix
              backend/webserver/middleware/users.js on lines 83..91

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

              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