server/controllers/request.js

Summary

Maintainability
D
2 days
Test Coverage

File request.js has 450 lines of code (exceeds 250 allowed). Consider refactoring.
Open

//
//   Copyright 2014 Ilkka Oksanen <iao@iki.fi>
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
Severity: Minor
Found in server/controllers/request.js - About 6 hrs to fix

    Function process has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    exports.process = async function process(session, command) {
      const { windowId } = command;
      const network = typeof command.network === 'string' ? command.network.toLowerCase() : null;
      const user = session.user;
    
    
    Severity: Minor
    Found in server/controllers/request.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 handleUpdate has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    async function handleUpdate({ user, command, window, session }) {
      const accepted = ['row', 'column', 'minimizedNamesList', 'desktop'];
      const acceptedAlerts = ['email', 'notification', 'sound', 'title'];
    
      if (!window) {
    Severity: Minor
    Found in server/controllers/request.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 handleCommand has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    async function handleCommand({ command, conversation, user, backend }) {
      const { command: name, params } = command;
    
      if (!conversation) {
        return { status: 'ERROR', errorMsg: 'Invalid windowId.' };
    Severity: Minor
    Found in server/controllers/request.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 process has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    exports.process = async function process(session, command) {
      const { windowId } = command;
      const network = typeof command.network === 'string' ? command.network.toLowerCase() : null;
      const user = session.user;
    
    
    Severity: Minor
    Found in server/controllers/request.js - About 1 hr to fix

      Function handleSet has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      async function handleSet({ user, command }) {
        const properties = command.settings || {};
        const keys = Object.keys(properties);
      
        if (keys.length === 0) {
      Severity: Minor
      Found in server/controllers/request.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 handleJoin has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      async function handleJoin({ user, command, backend, network }) {
        if (!command.name || !command.network) {
          return { status: 'PARAMETER_MISSING', errorMsg: 'Name or network missing.' };
        }
      
      
      Severity: Minor
      Found in server/controllers/request.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 courier.call(backend, 'textCommand', {
          userId: user.id,
          conversationId: conversation.id,
          command: name,
          commandParams: params
      Severity: Major
      Found in server/controllers/request.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

          return { status: 'OK' };
        Severity: Major
        Found in server/controllers/request.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return start1on1(user, targetUserGId, targetUserGId.isMASUser ? 'mas' : network);
          Severity: Major
          Found in server/controllers/request.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

              return { status: 'OK' };
            Severity: Major
            Found in server/controllers/request.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                    return { status: 'ERROR', errorMsg: 'Nick missing, use e.g. /ircquery john' };
              Severity: Major
              Found in server/controllers/request.js - About 30 mins to fix

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

                async function start1on1(user, targetUserGId, network) {
                  let selectedNetwork = network;
                
                  if (!targetUserGId || !targetUserGId.valid) {
                    return { status: 'ERROR', errorMsg: 'Malformed request.' };
                Severity: Minor
                Found in server/controllers/request.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