rsercano/mongoclient

View on GitHub
server/imports/core/connection/index.js

Summary

Maintainability
F
3 days
Test Coverage

Function getConnectionUrl has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
Open

  getConnectionUrl(connection, username, password, addAuthSource, keepDB) {
    if (connection.url) {
      if (username || password) ConnectionHelper.changeUsernameAndPasswordFromConnectionUrl(connection, username, password);
      if (!keepDB) ConnectionHelper.extractDBFromConnectionUrl(connection);
      else ConnectionHelper.putCorrectDBToConnectionUrl(connection);
Severity: Minor
Found in server/imports/core/connection/index.js - About 6 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

File index.js has 303 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Database, Logger, Error } from '/server/imports/modules';
import ConnectionHelper from './helper';

const fs = require('fs');
const mongodbUrlParser = require('mongodb-url');
Severity: Minor
Found in server/imports/core/connection/index.js - About 3 hrs to fix

    Function getConnectionUrl has 50 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      getConnectionUrl(connection, username, password, addAuthSource, keepDB) {
        if (connection.url) {
          if (username || password) ConnectionHelper.changeUsernameAndPasswordFromConnectionUrl(connection, username, password);
          if (!keepDB) ConnectionHelper.extractDBFromConnectionUrl(connection);
          else ConnectionHelper.putCorrectDBToConnectionUrl(connection);
    Severity: Minor
    Found in server/imports/core/connection/index.js - About 2 hrs to fix

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

        migrateConnectionsIfExist() {
          Logger.info({ message: 'migrate-connections' });
      
          const settings = Database.readOne({ type: Database.types.Settings, query: {} });
          if (settings.isMigrationDone) return;
      Severity: Minor
      Found in server/imports/core/connection/index.js - About 1 hr to fix

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

        const checkSSHOfConnection = function (connection) {
          if (connection.ssh) {
            if (!connection.ssh.enabled) delete connection.ssh;
            if (!connection.ssh.destinationPort) Error.create({ type: Error.types.MissingParameter, formatters: ['destination-port', 'ssh'], metadataToLog: connection });
            if (!connection.ssh.username) Error.create({ type: Error.types.MissingParameter, formatters: ['username', 'ssh'], metadataToLog: connection });
        Severity: Minor
        Found in server/imports/core/connection/index.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 setAuthToConnectionFromParsedUrl has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

        const setAuthToConnectionFromParsedUrl = function (connection, parsedUrl) {
          connection.authenticationType = parsedUrl.db_options.authMechanism ? parsedUrl.db_options.authMechanism.toLowerCase().replace(new RegExp('-', 'g'), '_') : '';
          if (connection.authenticationType) connection[connection.authenticationType] = {};
          if (parsedUrl.db_options.gssapiServiceName && connection.authenticationType === 'gssapi') connection.gssapi.serviceName = parsedUrl.db_options.gssapiServiceName;
          if (connection.authenticationType === 'mongodb_x509') delete connection.ssl;
        Severity: Minor
        Found in server/imports/core/connection/index.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 checkAuthenticationOfConnection has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        const checkAuthenticationOfConnection = function (connection) {
          if (connection.authenticationType !== 'scram_sha_1') delete connection.scram_sha_1;
          if (connection.authenticationType !== 'scram_sha_256') delete connection.scram_sha_256;
          if (connection.authenticationType !== 'mongodb_cr') delete connection.mongodb_cr;
          if (connection.authenticationType !== 'mongodb_x509') delete connection.mongodb_x509;
        Severity: Minor
        Found in server/imports/core/connection/index.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 getConnectionOptions has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          getConnectionOptions(connection) {
            const result = { useNewUrlParser: true, useUnifiedTopology: true };
            if (connection.authenticationType === 'mongodb_x509') addSSLOptions(connection.mongodb_x509, result);
            if (connection.ssl && connection.ssl.enabled) addSSLOptions(connection.ssl, result);
            if (connection.options && connection.options.connectWithNoPrimary) result.connectWithNoPrimary = true;
        Severity: Minor
        Found in server/imports/core/connection/index.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

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

        const setOptionsToConnectionFromParsedUrl = function (connection, parsedUrl) {
          if (parsedUrl.server_options) {
            connection.options.connectionTimeout = (parsedUrl.server_options.socketOptions && parsedUrl.server_options.socketOptions.connectTimeoutMS)
              ? parsedUrl.server_options.socketOptions.connectTimeoutMS : '';
            connection.options.socketTimeout = (parsedUrl.server_options.socketOptions && parsedUrl.server_options.socketOptions.socketTimeoutMS)
        Severity: Minor
        Found in server/imports/core/connection/index.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 getConnectionUrl has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          getConnectionUrl(connection, username, password, addAuthSource, keepDB) {
        Severity: Minor
        Found in server/imports/core/connection/index.js - About 35 mins to fix

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

          const migrateSSLPart = function (oldConnection, connection) {
            if (oldConnection.sslCertificatePath) {
              const objToChange = oldConnection.x509Username ? connection.mongodb_x509 : connection.ssl;
              objToChange.certificateFile = oldConnection.sslCertificate;
              objToChange.certificateFileName = oldConnection.sslCertificatePath;
          Severity: Minor
          Found in server/imports/core/connection/index.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

              connection.options.connectionTimeout = (parsedUrl.server_options.socketOptions && parsedUrl.server_options.socketOptions.connectTimeoutMS)
                ? parsedUrl.server_options.socketOptions.connectTimeoutMS : '';
          Severity: Major
          Found in server/imports/core/connection/index.js and 1 other location - About 1 hr to fix
          server/imports/core/connection/index.js on lines 26..27

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

          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

              connection.options.socketTimeout = (parsedUrl.server_options.socketOptions && parsedUrl.server_options.socketOptions.socketTimeoutMS)
                ? parsedUrl.server_options.socketOptions.socketTimeoutMS : '';
          Severity: Major
          Found in server/imports/core/connection/index.js and 1 other location - About 1 hr to fix
          server/imports/core/connection/index.js on lines 24..25

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

          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 (!connection.ssh.port) Error.create({ type: Error.types.MissingParameter, formatters: ['port', 'ssh'], metadataToLog: connection });
          Severity: Major
          Found in server/imports/core/connection/index.js and 3 other locations - About 50 mins to fix
          server/imports/core/connection/index.js on lines 69..69
          server/imports/core/connection/index.js on lines 70..70
          server/imports/core/connection/index.js on lines 71..71

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

          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 (!connection.ssh.destinationPort) Error.create({ type: Error.types.MissingParameter, formatters: ['destination-port', 'ssh'], metadataToLog: connection });
          Severity: Major
          Found in server/imports/core/connection/index.js and 3 other locations - About 50 mins to fix
          server/imports/core/connection/index.js on lines 70..70
          server/imports/core/connection/index.js on lines 71..71
          server/imports/core/connection/index.js on lines 72..72

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

          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 (!connection.ssh.username) Error.create({ type: Error.types.MissingParameter, formatters: ['username', 'ssh'], metadataToLog: connection });
          Severity: Major
          Found in server/imports/core/connection/index.js and 3 other locations - About 50 mins to fix
          server/imports/core/connection/index.js on lines 69..69
          server/imports/core/connection/index.js on lines 71..71
          server/imports/core/connection/index.js on lines 72..72

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

          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 (!connection.ssh.host) Error.create({ type: Error.types.MissingParameter, formatters: ['host', 'ssh'], metadataToLog: connection });
          Severity: Major
          Found in server/imports/core/connection/index.js and 3 other locations - About 50 mins to fix
          server/imports/core/connection/index.js on lines 69..69
          server/imports/core/connection/index.js on lines 70..70
          server/imports/core/connection/index.js on lines 72..72

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

          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

              Database.update({ type: Database.types.Settings, selector: {}, modifier: { $set: { isMigrationDone: true } } });
          Severity: Minor
          Found in server/imports/core/connection/index.js and 1 other location - About 40 mins to fix
          server/imports/core/settings/index.js on lines 75..75

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

          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