Showing 20 of 20 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
try {
await this.cloudWatchService.send(createLogGroupCommand);
this.logger.debug(`Log group '${logGroupName}' created successfully.`);
} catch (createLogGroupError) {
- 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 113.
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
try {
await this.cloudWatchService.send(createLogStreamCommand);
this.logger.debug(`Log stream '${logStreamName}' created successfully.`);
} catch (createLogStreamError) {
if (createLogStreamError.name === 'ResourceAlreadyExistsException') {
- 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 113.
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
File main.ts
has 329 lines of code (exceeds 250 allowed). Consider refactoring. Open
// @ts-ignore
import Fastly from '@tiagojsag/fastly-promises';
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
import type { Context, Middleware, Next, Request } from "koa";
import cors from "@koa/cors";
Function convertAndValidateBootstrapOptions
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
private static convertAndValidateBootstrapOptions(options: BootstrapArguments): ConfigurationOptions {
if (
options.fastlyEnabled !== true
&& options.fastlyEnabled !== false
&& options.fastlyEnabled !== "true"
- 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 convertAndValidateBootstrapOptions
has 71 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static convertAndValidateBootstrapOptions(options: BootstrapArguments): ConfigurationOptions {
if (
options.fastlyEnabled !== true
&& options.fastlyEnabled !== false
&& options.fastlyEnabled !== "true"
Function bootstrap
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public bootstrap(opts: BootstrapArguments): Middleware<{}, {}> {
this.options = Microservice.convertAndValidateBootstrapOptions(opts);
this.options.logger.info('RW API integration middleware registered');
if (this.options.awsCloudWatchLoggingEnabled) {
this.cloudWatchService = CloudWatchService.init(this.options.logger, this.options.awsRegion, this.options.awsCloudWatchLogGroupName, this.options.awsCloudWatchLogStreamName);
- 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 fastlyIntegrationHandler
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
private static async fastlyIntegrationHandler(ctx: Context, fastlyServiceId: string, fastlyAPIKey: string, logger: Logger): Promise<void> {
const fastly: Fastly = Fastly(fastlyAPIKey, fastlyServiceId);
if (ctx.status >= 200 && ctx.status < 400) {
// Non-GET, anonymous requests with the `uncache` header can purge the cache
- 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 requestToMicroservice
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public async requestToMicroservice(requestConfig: RequestToMicroserviceOptions): Promise<Record<string, any>> {
this.options.logger.info('Adding authorization header');
const axiosRequestConfig: AxiosRequestConfig = {
baseURL: this.options.gatewayURL,
data: requestConfig.body,
- 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 logRequestToCloudWatch
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
private async logRequestToCloudWatch(logger: Logger, request: Request, requestValidationData: RequestValidationResponse): Promise<void> {
logger.debug('[logRequestToCloudWatch] Logging request to CloudWatch');
const logQuery: Record<string, any> = { ...request.query };
delete logQuery.loggedUser;
Function bootstrap
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
public bootstrap(opts: BootstrapArguments): Middleware<{}, {}> {
this.options = Microservice.convertAndValidateBootstrapOptions(opts);
this.options.logger.info('RW API integration middleware registered');
if (this.options.awsCloudWatchLoggingEnabled) {
this.cloudWatchService = CloudWatchService.init(this.options.logger, this.options.awsRegion, this.options.awsCloudWatchLogGroupName, this.options.awsCloudWatchLogStreamName);
Function requestToMicroservice
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
public async requestToMicroservice(requestConfig: RequestToMicroserviceOptions): Promise<Record<string, any>> {
this.options.logger.info('Adding authorization header');
const axiosRequestConfig: AxiosRequestConfig = {
baseURL: this.options.gatewayURL,
data: requestConfig.body,
Function getRequestValidationData
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
private async getRequestValidationData(logger: Logger, baseURL: string, request: Request): Promise<RequestValidationResponse> {
logger.debug('[getLoggedUser] Validating request');
if (!request.header.authorization) {
logger.debug('[getLoggedUser] No authorization header found');
}
Function getRequestValidationData
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
private async getRequestValidationData(logger: Logger, baseURL: string, request: Request): Promise<RequestValidationResponse> {
logger.debug('[getLoggedUser] Validating request');
if (!request.header.authorization) {
logger.debug('[getLoggedUser] No authorization header found');
}
- 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 bootstrapMiddleware
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
const bootstrapMiddleware: Middleware = async (ctx: Context, next: Next) => {
const { logger, gatewayURL } = this.options;
if (!this.shouldSkipAPIKeyValidation(ctx)) {
try {
Function injectRequestValidationData
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private async injectRequestValidationData(logger: Logger, requestValidationData: RequestValidationResponse, ctx: Context): Promise<void> {
logger.debug('[injectRequestValidationData] Obtaining loggedUser for microserviceToken');
if (requestValidationData.application) {
ctx.state.requestApplication = requestValidationData.application
}
- 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 logRequestToCloudWatch
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private async logRequestToCloudWatch(logger: Logger, request: Request, requestValidationData: RequestValidationResponse): Promise<void> {
logger.debug('[logRequestToCloudWatch] Logging request to CloudWatch');
const logQuery: Record<string, any> = { ...request.query };
delete logQuery.loggedUser;
- 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
Avoid too many return
statements within this function. Open
return {
statusCode: err.response.status,
body: err.response.data
};
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (requestConfig.resolveWithFullResponse === true) {
return {
statusCode: err.response.status,
body: err.response.data
};
- 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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (requestConfig.resolveWithFullResponse === true) {
return {
statusCode: err.response.status,
body: err.response.data
};
- 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
Avoid too many return
statements within this function. Open
return err;