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;
- Read upRead up
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,
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 {
- Read upRead up
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) {
Avoid deeply nested control flow statements. Open
if (targetType === 'party') {
partyMembers = await castPartySpell(req, party, user, spell, quantity);
} else {
partyMembers = await castUserSpell(
res,
Function castTaskSpell
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
async function castTaskSpell (res, req, targetId, user, spell, quantity = 1) {
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
Avoid deeply nested control flow statements. Open
if (isV3) userToJson = await userToJson.toJSONWithInbox();
Function castPartySpell
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
async function castPartySpell (req, party, user, spell, quantity = 1) {
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) {
- Read upRead up
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"