server/backends/irc/controller.js

Summary

Maintainability
F
6 days
Test Coverage

File controller.js has 1001 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env node
//
//   Copyright 2009-2014 Ilkka Oksanen <iao@iki.fi>
//
//   Licensed under the Apache License, Version 2.0 (the "License");
Severity: Major
Found in server/backends/irc/controller.js - About 2 days to fix

    Function handleMode has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
    Open

    async function handleMode(user, msg) {
      // :ilkka9!~ilkka9@localhost.myrootshell.com MODE #sunnuntai +k foobar3
      const target = msg.params[0];
    
      if (!isChannel(target)) {
    Severity: Minor
    Found in server/backends/irc/controller.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

    Function handleMode has 66 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    async function handleMode(user, msg) {
      // :ilkka9!~ilkka9@localhost.myrootshell.com MODE #sunnuntai +k foobar3
      const target = msg.params[0];
    
      if (!isChannel(target)) {
    Severity: Major
    Found in server/backends/irc/controller.js - About 2 hrs to fix

      Function updateNick has 55 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      async function updateNick(user, network, oldNick, newNick) {
        let changed = false;
        let targetUserGId = null;
        const nickUser = await nicksService.getUser(oldNick, network);
      
      
      Severity: Major
      Found in server/backends/irc/controller.js - About 2 hrs to fix

        Function updateNick has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        async function updateNick(user, network, oldNick, newNick) {
          let changed = false;
          let targetUserGId = null;
          const nickUser = await nicksService.getUser(oldNick, network);
        
        
        Severity: Minor
        Found in server/backends/irc/controller.js - About 2 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 handlePrivmsg has 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        async function handlePrivmsg(user, msg, command) {
          // :ilkkao!~ilkkao@127.0.0.1 NOTICE buppe :foo
          const target = msg.params[0];
          const currentNick = await nicksService.getNick(user.gId, msg.network);
          let conversation;
        Severity: Minor
        Found in server/backends/irc/controller.js - About 1 hr to fix

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

          async function handleJoin(user, msg) {
            // :neo!i=ilkkao@iao.iki.fi JOIN :#testi4
            const channel = msg.params[0];
            const network = msg.network;
            const targetUser = await nicksService.getUser(msg.nick, network);
          Severity: Minor
          Found in server/backends/irc/controller.js - About 1 hr to fix

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

            async function parseIrcMessage({ userId, line, network }) {
              const parts = line.trim().split(' ');
              const msg = {
                params: [],
                numericReply: false,
            Severity: Minor
            Found in server/backends/irc/controller.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 handlePrivmsg has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

            async function handlePrivmsg(user, msg, command) {
              // :ilkkao!~ilkkao@127.0.0.1 NOTICE buppe :foo
              const target = msg.params[0];
              const currentNick = await nicksService.getNick(user.gId, msg.network);
              let conversation;
            Severity: Minor
            Found in server/backends/irc/controller.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 handle376or422 has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            async function handle376or422(user, msg) {
              const networkInfo = await findOrCreateNetworkInfo(user, msg.network);
            
              await addSystemMessage(user, msg.network, 'server', msg.params.join(' '));
            
            
            Severity: Minor
            Found in server/backends/irc/controller.js - About 1 hr to fix

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

              async function handleJoin(user, msg) {
                // :neo!i=ilkkao@iao.iki.fi JOIN :#testi4
                const channel = msg.params[0];
                const network = msg.network;
                const targetUser = await nicksService.getUser(msg.nick, network);
              Severity: Minor
              Found in server/backends/irc/controller.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 disconnectIfIdle has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

              async function disconnectIfIdle(user, network) {
                const windows = await windowsService.getWindowsForNetwork(user, network);
                let onlyServer1on1Left = false;
              
                if (windows.length === 1) {
              Severity: Minor
              Found in server/backends/irc/controller.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

              Avoid deeply nested control flow statements.
              Open

                        if (oper === '+') {
                          // Non-oper got voice
                          newClass = VOICE;
                        } else {
                          // Non-oper lost voice
              Severity: Major
              Found in server/backends/irc/controller.js - About 45 mins to fix

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

                async function processDisconnected({ userId, network, reason }) {
                  const user = await User.fetch(userId);
                  const networkInfo = await findOrCreateNetworkInfo(user, network);
                  const previousState = networkInfo.get('state');
                
                
                Severity: Minor
                Found in server/backends/irc/controller.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

                async function handleTopic(user, msg) {
                  // :ilkka!ilkkao@localhost.myrootshell.com TOPIC #portaali :My new topic
                  const channel = msg.params[0];
                  const topic = msg.params[1];
                  const conversation = await Conversation.findFirst({
                Severity: Major
                Found in server/backends/irc/controller.js and 1 other location - About 3 hrs to fix
                server/backends/irc/controller.js on lines 601..614

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

                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

                async function handle332(user, msg) {
                  // :portaali.org 332 ilkka #portaali :Cool topic
                  const channel = msg.params[0];
                  const topic = msg.params[1];
                  const conversation = await Conversation.findFirst({
                Severity: Major
                Found in server/backends/irc/controller.js and 1 other location - About 3 hrs to fix
                server/backends/irc/controller.js on lines 1031..1044

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

                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

                function sendPrivmsg(user, network, target, text) {
                  courier.callNoWait('connectionmanager', 'write', {
                    userId: user.id,
                    network,
                    line: `PRIVMSG ${target} :${text}`
                Severity: Major
                Found in server/backends/irc/controller.js and 1 other location - About 1 hr to fix
                server/backends/irc/controller.js on lines 1339..1345

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

                function sendJoin(user, network, channel, password) {
                  courier.callNoWait('connectionmanager', 'write', {
                    userId: user.id,
                    network,
                    line: `JOIN ${channel} ${password}`
                Severity: Major
                Found in server/backends/irc/controller.js and 1 other location - About 1 hr to fix
                server/backends/irc/controller.js on lines 1331..1337

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

                async function handle319(user, msg) {
                  // :irc.localhost 319 ilkka_ Mika7 :#portaali @#hemmot @#ilves #ceeassa
                  const channels = msg.params[1];
                
                  await addSystemMessage(user, msg.network, 'server', `--- on channels ${channels}`);
                Severity: Minor
                Found in server/backends/irc/controller.js and 1 other location - About 50 mins to fix
                server/backends/irc/controller.js on lines 711..716

                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

                async function handle482(user, msg) {
                  // irc.localhost 482 ilkka #test2 :You're not channel operator
                  const channel = msg.params[0];
                
                  await addSystemMessage(user, msg.network, 'error', `You're not channel operator on ${channel}`);
                Severity: Minor
                Found in server/backends/irc/controller.js and 1 other location - About 50 mins to fix
                server/backends/irc/controller.js on lines 594..599

                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

                There are no issues that match your filters.

                Category
                Status