bbyars/mountebank

View on GitHub
src/models/http/baseHttpServer.js

Summary

Maintainability
F
3 days
Test Coverage
F
8%

Function exports has 154 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function (createBaseServer) {

    function create (options, logger, responseFn) {
        const connections = {},
            defaultResponse = options.defaultResponse || {};
Severity: Major
Found in src/models/http/baseHttpServer.js - About 6 hrs to fix

    Function create has 134 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        function create (options, logger, responseFn) {
            const connections = {},
                defaultResponse = options.defaultResponse || {};
    
            function postProcess (stubResponse, request) {
    Severity: Major
    Found in src/models/http/baseHttpServer.js - About 5 hrs to fix

      Function exports has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

      module.exports = function (createBaseServer) {
      
          function create (options, logger, responseFn) {
              const connections = {},
                  defaultResponse = options.defaultResponse || {};
      Severity: Minor
      Found in src/models/http/baseHttpServer.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 postProcess has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              function postProcess (stubResponse, request) {
                  /* eslint complexity: 0 */
                  const defaultHeaders = defaultResponse.headers || {},
                      response = {
                          statusCode: stubResponse.statusCode || defaultResponse.statusCode || 200,
      Severity: Minor
      Found in src/models/http/baseHttpServer.js - About 1 hr to fix

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

                    if (socket.on) {
                        connections[name] = socket;
        
                        socket.on('error', error => {
                            logger.error('%s transmission error X=> %s', name, JSON.stringify(error));
        Severity: Major
        Found in src/models/http/baseHttpServer.js and 1 other location - About 4 hrs to fix
        src/models/smtp/smtpServer.js on lines 25..40

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

        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

                    server.on('error', error => {
                        if (error.errno === 'EADDRINUSE') {
                            reject(errors.ResourceConflictError(`Port ${options.port} is already in use`));
                        }
                        else if (error.errno === 'EACCES') {
        Severity: Major
        Found in src/models/http/baseHttpServer.js and 1 other location - About 3 hrs to fix
        src/models/tcp/tcpServer.js on lines 120..130

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

        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

                            close: callback => {
                                server.close(callback);
                                Object.keys(connections).forEach(socket => {
                                    connections[socket].destroy();
                                });
        Severity: Major
        Found in src/models/http/baseHttpServer.js and 1 other location - About 1 hr to fix
        src/models/smtp/smtpServer.js on lines 85..90

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

                        client.on('error', err => {
                            logger.warn('CLIENT TO PROXY ERROR: [%s] %s', err.code, err.message);
                            logger.debug('%s', err.stack);
                        });
        Severity: Major
        Found in src/models/http/baseHttpServer.js and 1 other location - About 1 hr to fix
        src/models/http/baseHttpServer.js on lines 85..88

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

        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

                        proxyServer.on('error', err => {
                            logger.warn('SERVER PROXY ERROR: [%s] %s', err.code, err.message);
                            logger.debug('%s', err.stack);
                        });
        Severity: Major
        Found in src/models/http/baseHttpServer.js and 1 other location - About 1 hr to fix
        src/models/http/baseHttpServer.js on lines 81..84

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

        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

        Parsing error: Invalid ecmaVersion.
        Open

        'use strict';
        Severity: Minor
        Found in src/models/http/baseHttpServer.js by eslint

        For more information visit Source: http://eslint.org/docs/rules/

        There are no issues that match your filters.

        Category
        Status