HabitRPG/habitrpg

View on GitHub
website/server/controllers/api-v3/chat.js

Summary

Maintainability
D
2 days
Test Coverage

Function handler has 109 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  async handler (req, res) {
    const { user } = res.locals;
    const { groupId } = req.params;

    req.checkParams('groupId', apiError('groupIdRequired')).notEmpty();
Severity: Major
Found in website/server/controllers/api-v3/chat.js - About 4 hrs to fix

    Function handler has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

      async handler (req, res) {
        const { user } = res.locals;
        const { groupId } = req.params;
    
        req.checkParams('groupId', apiError('groupIdRequired')).notEmpty();
    Severity: Minor
    Found in website/server/controllers/api-v3/chat.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

    File chat.js has 291 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import moment from 'moment';
    import nconf from 'nconf';
    import { authWithHeaders } from '../../middlewares/auth';
    import { model as Group } from '../../models/group';
    import { model as User } from '../../models/user';
    Severity: Minor
    Found in website/server/controllers/api-v3/chat.js - About 3 hrs to fix

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

        async handler (req, res) {
          const { user } = res.locals;
          const { groupId } = req.params;
          const { chatId } = req.params;
      
      
      Severity: Minor
      Found in website/server/controllers/api-v3/chat.js - About 1 hr to fix

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

          async handler (req, res) {
            const { user } = res.locals;
            const { groupId } = req.params;
            const { chatId } = req.params;
        
        
        Severity: Minor
        Found in website/server/controllers/api-v3/chat.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

            user.notifications = user.notifications.filter(n => {
              if (n && n.type === 'NEW_CHAT_MESSAGE' && n.data && n.data.group && n.data.group.id === groupId) {
                return false;
              }
        
        
        Severity: Major
        Found in website/server/controllers/api-v3/chat.js and 1 other location - About 2 hrs to fix
        website/server/controllers/api-v3/groups.js on lines 817..823

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

        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

        api.flagChat = {
          method: 'POST',
          url: '/groups/:groupId/chat/:chatId/flag',
          middlewares: [authWithHeaders()],
          async handler (req, res) {
        Severity: Major
        Found in website/server/controllers/api-v3/chat.js and 1 other location - About 2 hrs to fix
        website/server/controllers/api-v3/members.js on lines 814..823

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

        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

            const chatUpdated = !!(
              lastClientMsg && group.chat && group.chat[0] && group.chat[0].id !== lastClientMsg
            );
        Severity: Minor
        Found in website/server/controllers/api-v3/chat.js and 1 other location - About 50 mins to fix
        website/server/controllers/api-v3/chat.js on lines 175..177

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

        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

            const chatUpdated = !!(
              lastClientMsg && group.chat && group.chat[0] && group.chat[0].id !== lastClientMsg
            );
        Severity: Minor
        Found in website/server/controllers/api-v3/chat.js and 1 other location - About 50 mins to fix
        website/server/controllers/api-v3/chat.js on lines 519..521

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

        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