seeden/maglev

View on GitHub
src/app.js

Summary

Maintainability
D
2 days
Test Coverage

File app.js has 347 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import express from 'express';
import debug from 'debug';
import http from 'http';
import isArray from 'lodash/isArray';

Severity: Minor
Found in src/app.js - About 4 hrs to fix

    App has 21 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export default class App {
      constructor(server, options = {}) {
        if (!options.root) {
          throw new Error('Root is undefined');
        }
    Severity: Minor
    Found in src/app.js - About 2 hrs to fix

      Function _prepareSession has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        _prepareSession() {
          const app = this.expressApp;
          const options = this.options;
      
          if (!options.session) {
      Severity: Minor
      Found in src/app.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 _prepareStatic has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        _prepareStatic() {
          const app = this.expressApp;
          const options = this.options;
      
          if (options.flash) {
      Severity: Minor
      Found in src/app.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 _prepareStatic has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _prepareStatic() {
          const app = this.expressApp;
          const options = this.options;
      
          if (options.flash) {
      Severity: Minor
      Found in src/app.js - About 1 hr to fix

        Function close has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          close(callback) {
            const { activeConnections, httpServer, options } = this;
        
            if (!httpServer) {
              return callback(new Error('You need to listen first'));
        Severity: Minor
        Found in src/app.js - About 1 hr to fix

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

            handleConnectionEvents() {
              // TODO UNHANDLE
              const { activeConnections, httpServer } = this;
          
              httpServer.on('connection', function onConnectionCallback(connection) {
          Severity: Minor
          Found in src/app.js - About 1 hr to fix

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

              _prepareSession() {
                const app = this.expressApp;
                const options = this.options;
            
                if (!options.session) {
            Severity: Minor
            Found in src/app.js - About 1 hr to fix

              Function _prepareHtml has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                _prepareHtml() {
                  const app = this.expressApp;
                  const options = this.options;
              
                  if (!options.powered) {
              Severity: Minor
              Found in src/app.js - About 1 hr to fix

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

                  _prepareHtml() {
                    const app = this.expressApp;
                    const options = this.options;
                
                    if (!options.powered) {
                Severity: Minor
                Found in src/app.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 handleConnectionEvents has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  handleConnectionEvents() {
                    // TODO UNHANDLE
                    const { activeConnections, httpServer } = this;
                
                    httpServer.on('connection', function onConnectionCallback(connection) {
                Severity: Minor
                Found in src/app.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 prepareRequest has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                function prepareRequest(req) {
                  req.__defineGetter__('httpHost', function getHttpHost() {
                    const trustProxy = this.app.get('trust proxy');
                    const host = trustProxy && this.get('X-Forwarded-Host');
                
                
                Severity: Minor
                Found in src/app.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

                There are no issues that match your filters.

                Category
                Status