Showing 107 of 123 total issues
File LocalState.ts
has 656 lines of code (exceeds 250 allowed). Consider refactoring. Open
/* eslint-disable max-lines */
import { doesExist, InvalidArgumentError, isNone, mustDefault, mustExist, mustFind } from '@apextoaster/js-utils';
import { Container, Inject, Logger } from 'noicejs';
import { NotInitializedError } from '../../error/NotInitializedError.js';
Function populateRoom
has a Cognitive Complexity of 60 (exceeds 6 allowed). Consider refactoring. Open
public async populateRoom(firstRoom: Room, searchRooms: Array<Room>, max: number): Promise<Array<Room>> {
if (max <= 0) {
return [];
}
- 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 step
has a Cognitive Complexity of 40 (exceeds 6 allowed). Consider refactoring. Open
public async step(): Promise<StepResult> {
if (isNone(this.state)) {
throw new NotInitializedError('state has not been initialized');
}
- 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 EntityGenerator.ts
has 394 lines of code (exceeds 250 allowed). Consider refactoring. Open
import { doesExist, mergeMap, mustExist, setOrPush } from '@apextoaster/js-utils';
import { Inject, Logger } from 'noicejs';
import { equipItems, isDestPortal, zeroStep } from './index.js';
import { WorldEntityType } from '../../model/entity/index.js';
Function findMatching
has a Cognitive Complexity of 32 (exceeds 6 allowed). Consider refactoring. Open
export function findMatching<TType extends WorldEntityType>(rooms: ReadonlyArray<ReadonlyRoom>, search: SearchFilter<TType>): Array<Immutable<EntityForType<TType>>> {
const matchers = mustDefault(search.matchers, createStrictMatcher<TType>());
const results: Array<EntityForType<TType>> = [];
for (const room of rooms) {
- 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 findContainer
has a Cognitive Complexity of 28 (exceeds 6 allowed). Consider refactoring. Open
export function findContainer<TType extends ActorType | RoomType>(state: WorldState, search: SearchFilter<TType>): Array<Actor | Room> {
const matchers = mustDefault(search.matchers, createStrictMatcher<TType>());
const results = new Set<Actor | Room>();
for (const room of state.rooms) {
- 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 step
has 96 lines of code (exceeds 30 allowed). Consider refactoring. Open
public async step(): Promise<StepResult> {
if (isNone(this.state)) {
throw new NotInitializedError('state has not been initialized');
}
Function populateRoom
has 94 lines of code (exceeds 30 allowed). Consider refactoring. Open
public async populateRoom(firstRoom: Room, searchRooms: Array<Room>, max: number): Promise<Array<Room>> {
if (max <= 0) {
return [];
}
LocalStateService
has 25 functions (exceeds 20 allowed). Consider refactoring. Open
@Inject(
INJECT_COUNTER,
INJECT_EVENT,
INJECT_LOGGER,
INJECT_RANDOM,
File TestPlayerActor.ts
has 273 lines of code (exceeds 250 allowed). Consider refactoring. Open
import { expect } from 'chai';
import { BaseOptions } from 'noicejs';
import { makeCommand, makeCommandIndex } from '../../../src/model/Command.js';
import { INJECT_EVENT, INJECT_LOCALE } from '../../../src/module/index.js';
StateEntityGenerator
has 21 functions (exceeds 20 allowed). Consider refactoring. Open
@Inject(INJECT_COUNTER, INJECT_LOGGER, INJECT_RANDOM, INJECT_TEMPLATE)
export class StateEntityGenerator {
protected counter: Counter;
protected logger: Logger;
protected random: RandomService;
Function main
has 55 lines of code (exceeds 30 allowed). Consider refactoring. Open
export async function main(args: Array<string>): Promise<number> {
// parse args
const arg = parseArgs(args);
// load config and create logger
Function onJoin
has 51 lines of code (exceeds 30 allowed). Consider refactoring. Open
public async onJoin(event: ActorJoinEvent): Promise<void> {
const generator = mustExist(this.generator);
const state = mustExist(this.state);
const world = mustExist(this.world);
Function create
has 50 lines of code (exceeds 30 allowed). Consider refactoring. Open
public async create(config: ConfigServices): Promise<void> {
for (const state of config.states) {
if (this.services.has(state.name)) {
throw new InvalidArgumentError('state service already exists');
}
Function create
has a Cognitive Complexity of 15 (exceeds 6 allowed). Consider refactoring. Open
public async create(config: ConfigServices): Promise<void> {
for (const state of config.states) {
if (this.services.has(state.name)) {
throw new InvalidArgumentError('state service already exists');
}
- 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 VerbActorMove
has 46 lines of code (exceeds 30 allowed). Consider refactoring. Open
export async function VerbActorMove(this: ScriptTarget, context: ScriptContext): Promise<void> {
const actor = assertActor(this);
// find the new room
const command = mustExist(context.command);
Function VerbActorPush
has 45 lines of code (exceeds 30 allowed). Consider refactoring. Open
export async function VerbActorPush(this: ScriptTarget, context: ScriptContext): Promise<void> {
assertActor(this);
const command = mustExist(context.command);
Function moveRoom
has 44 lines of code (exceeds 30 allowed). Consider refactoring. Open
public async moveRoom(transfer: RoomTransfer, context: ScriptContext): Promise<void> {
const { source, target } = transfer;
if (!isRoom(source)) {
throw new InvalidArgumentError('source entity must be a room');
Similar blocks of code found in 2 locations. Consider refactoring. Open
const world: WorldTemplate = {
...TEST_WORLD,
templates: {
actors: [{
base: {
- Read upRead up
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 246.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
const world: WorldTemplate = {
...TEST_WORLD,
templates: {
actors: [{
base: {
- Read upRead up
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 246.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76