Function navigate
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public navigate(navigation: INavigation | Navigation): Promise<boolean> {
if (!(navigation instanceof Navigation)) {
navigation = Navigation.create(navigation);
}
const navigationFlags = new NavigationFlags();
- 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 finalize
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public async finalize(navigation: Navigation, isLast: boolean): Promise<void> {
// If this navigation shouldn't be added to history...
if (navigation.untracked ?? false) {
// ...and it's a navigation from the browser (back, forward, url)...
if ((navigation.fromBrowser ?? false) && this.options.store != null) {
- 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 navigator.ts
has 286 lines of code (exceeds 250 allowed). Consider refactoring. Open
import { EventAggregator, IContainer, IEventAggregator, resolve } from '@aurelia/kernel';
import { IRouteableComponent } from './interfaces';
import { RoutingInstruction } from './instructions/routing-instruction';
import { Navigation, IStoredNavigation, INavigation, NavigationFlags } from './navigation';
import { Runner, Step } from './utilities/runner';
Function navigate
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
public navigate(navigation: INavigation | Navigation): Promise<boolean> {
if (!(navigation instanceof Navigation)) {
navigation = Navigation.create(navigation);
}
const navigationFlags = new NavigationFlags();
Function saveState
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public async saveState(index: number, push: boolean): Promise<boolean | void> {
// Make sure all navigations are clean of non-persisting data
for (let i = 0; i < this.navigations.length; i++) {
this.navigations[i] = Navigation.create(this.navigations[i].toStoredNavigation());
}
- 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 serializeNavigation
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
private async serializeNavigation(navigation: Navigation, preservedNavigations: Navigation[]): Promise<void> {
let excludeComponents = [];
// Components in preserved navigations should not be serialized/freed
for (const preservedNavigation of preservedNavigations) {
// Get components from instruction...
Avoid deeply nested control flow statements. Open
if (typeof navig.instruction !== 'string' || typeof navig.fullStateInstruction !== 'string') {
// Use serialize to dispose routing instruction components
// since the end result is the same. Pass the navigations
// that should be preserved so that components in them aren't
// disposed if they also exist in discarded routing instructions.
Function serializeNavigation
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private async serializeNavigation(navigation: Navigation, preservedNavigations: Navigation[]): Promise<void> {
let excludeComponents = [];
// Components in preserved navigations should not be serialized/freed
for (const preservedNavigation of preservedNavigations) {
// Get components from instruction...
- 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 cancel
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public async cancel(navigation: Navigation): Promise<void> {
if (this.options.store != null) {
// If it's a new navigation...
if (navigation.navigation?.new) {
// ...from the browser (url)...
- 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 freeInstructionComponents
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private freeInstructionComponents(instruction: RoutingInstruction, excludeComponents: IRouteableComponent[], alreadyDone: IRouteableComponent[]): void | Promise<void> {
const component = instruction.component.instance;
const viewport = instruction.viewport?.instance as Viewport ?? null;
// Both viewport and component instance should be set in order to free/dispose
if (component === null || viewport === null || alreadyDone.some(done => done === component)) {
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (typeof preservedNavigation.fullStateInstruction !== 'string') {
excludeComponents.push(...RoutingInstruction.flat(preservedNavigation.fullStateInstruction)
.filter(instruction => instruction.endpoint.instance !== null) // Both endpoint instance and...
.map(instruction => instruction.component.instance)); // ...component instance should be set
}
- 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 79.
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
if (typeof preservedNavigation.instruction !== 'string') {
excludeComponents.push(...RoutingInstruction.flat(preservedNavigation.instruction)
.filter(instruction => instruction.endpoint.instance !== null) // Both endpoint instance and...
.map(instruction => instruction.component.instance)); // ...component instance should be set
}
- 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 79.
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
export interface IStoredNavigatorState {
state?: Record<string, unknown>;
navigations: IStoredNavigation[];
navigationIndex: number;
}
- 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 45.
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
export interface INavigatorState {
state?: Record<string, unknown>;
navigations: Navigation[];
navigationIndex: number;
}
- 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 45.
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