HabitRPG/habitrpg

View on GitHub
website/server/libs/spells.js

Summary

Maintainability
D
2 days
Test Coverage

Function castSpell has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
Open

async function castSpell (req, res, { isV3 = false }) {
  const { user } = res.locals;
  const { spellId } = req.params;
  const { targetId } = req.query;
  const quantity = req.body.quantity || 1;
Severity: Minor
Found in website/server/libs/spells.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

File spells.js has 280 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { model as User } from '../models/user';
import { chatModel as Chat } from '../models/message';
import * as Tasks from '../models/task';
import {
  NotFound,
Severity: Minor
Found in website/server/libs/spells.js - About 2 hrs to fix

    Function castUserSpell has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    async function castUserSpell (res, req, party, targetId, user, spell, quantity = 1) {
      let partyMembers;
      if (!party && (!targetId || user._id === targetId)) {
        partyMembers = user;
      } else {
    Severity: Minor
    Found in website/server/libs/spells.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 castUserSpell has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    async function castUserSpell (res, req, party, targetId, user, spell, quantity = 1) {
    Severity: Major
    Found in website/server/libs/spells.js - About 50 mins to fix

      Avoid deeply nested control flow statements.
      Open

          if (targetType === 'party') {
            partyMembers = await castPartySpell(req, party, user, spell, quantity);
          } else {
            partyMembers = await castUserSpell(
              res,
      Severity: Major
      Found in website/server/libs/spells.js - About 45 mins to fix

        Function castTaskSpell has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        async function castTaskSpell (res, req, targetId, user, spell, quantity = 1) {
        Severity: Minor
        Found in website/server/libs/spells.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

              if (party && !spell.silent) {
                const lastMessage = await Chat.findOne({ groupId: party._id })
                  .sort('-timestamp')
                  .exec();
                if (targetType === 'user') { // Single target spell, check for repeat
          Severity: Major
          Found in website/server/libs/spells.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                if (isV3) userToJson = await userToJson.toJSONWithInbox();
            Severity: Major
            Found in website/server/libs/spells.js - About 45 mins to fix

              Function castPartySpell has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              async function castPartySpell (req, party, user, spell, quantity = 1) {
              Severity: Minor
              Found in website/server/libs/spells.js - About 35 mins to fix

                Function castPartySpell has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                async function castPartySpell (req, party, user, spell, quantity = 1) {
                  let partyMembers;
                  if (spell.bulk) {
                    const data = { };
                    if (party) {
                Severity: Minor
                Found in website/server/libs/spells.js - About 35 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