Showing 126 of 126 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (body.iso) {
iso.country = body.iso ? body.iso.country : null;
iso.region = body.iso ? body.iso.region : null;
}
- 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 69.
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 (body.use) {
use.id = body.use ? body.use.id : null;
use.name = body.use ? body.use.name : null;
}
- 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 69.
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
Function update
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async update(ctx) {
logger.info(`Updating area with id ${ctx.params.id}`);
const area = await AreaModel.findById(ctx.params.id);
const { files } = ctx.request;
if (ctx.request.body.application || !area.application) {
Function exports
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = (() => {
const loadAPI = (app, path, pathApi) => {
const routesFiles = fs.readdirSync(path);
let existIndexRouter = false;
Function get
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async get(ctx) {
logger.info(`Obtaining v2 area with areaId ${ctx.params.id}`);
if (!mongoose.Types.ObjectId.isValid(ctx.params.id)) {
ctx.throw(404, 'Area not found');
Function getRequestBodyForSubscriptionFromArea
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
static getRequestBodyForSubscriptionFromArea(area) {
const body = {
name: area.name,
datasets: SubscriptionsService.getDatasetsForSubscription(area),
language: area.language,
Function get
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
static async get(ctx) {
logger.info(`Obtaining v2 area with areaId ${ctx.params.id}`);
if (!mongoose.Types.ObjectId.isValid(ctx.params.id)) {
ctx.throw(404, 'Area not 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 saveArea
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
static async saveArea(ctx, userId) {
logger.info('Saving area');
let image = '';
if (ctx.request.files && ctx.request.files.image && ctx.request.files.image.s3Url) {
image = ctx.request.files.image.s3Url;
- 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 groupPoints
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
static groupPoints(dataViirs, dataGlad, precisionBbox) {
logger.debug('Group points', ' and precisionBbox ', precisionBbox);
const result = {};
if (dataViirs) {
for (let i = 0, { length } = dataViirs; i < length; i++) {
- 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 groupPoints
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
static groupPoints(dataViirs, dataGlad, precisionBbox) {
logger.debug('Group points', ' and precisionBbox ', precisionBbox);
const result = {};
if (dataViirs) {
for (let i = 0, { length } = dataViirs; i < length; i++) {
Function update
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async update(ctx, next) {
logger.debug('Validating body for update area');
ctx.checkBody('name').optional().len(2, 100);
ctx.checkBody('application').optional().check((application) => AreaValidatorV2.notEmptyString(application), 'cannot be empty');
Function deleteByUserId
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async deleteByUserId(ctx) {
logger.info(`Deleting areas of user with id ${ctx.params.userId}`);
const userIdToDelete = ctx.params.userId;
try {
Function delete
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async delete(ctx) {
logger.info(`Deleting area with id ${ctx.params.id}`);
const areaToDelete = await AreaModel.findById(ctx.params.id);
if (areaToDelete) {
if (areaToDelete.subscriptionId) {
Function getFilteredQuery
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
static getFilteredQuery(query, ids = []) {
const areaAttributes = Object.keys(Area.schema.obj);
logger.debug(`[getFilteredQuery] areaAttributes: ${areaAttributes}`);
Object.keys(query).forEach((param) => {
if (areaAttributes.indexOf(param) < 0) {
Function create
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async create(ctx, next) {
logger.debug('Validating body for create area');
ctx.checkBody('name').notEmpty().len(1, 100);
ctx.checkBody('application').optional().check((application) => AreaValidatorV2.notEmptyString(application), 'cannot be empty');
Identical blocks of code found in 2 locations. Consider refactoring. Open
try {
await UserService.getUserById(userIdToDelete, ctx.request.headers['x-api-key']);
} catch (error) {
ctx.throw(404, `User ${userIdToDelete} does not exist`);
}
- 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 61.
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
try {
await UserService.getUserById(userIdToDelete, ctx.request.headers['x-api-key']);
} catch (error) {
ctx.throw(404, `User ${userIdToDelete} does not exist`);
}
- 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 61.
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
Function loadAPI
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
const loadAPI = (app, path, pathApi) => {
const routesFiles = fs.readdirSync(path);
let existIndexRouter = false;
routesFiles.forEach((file) => {
const newPath = path ? (`${path}/${file}`) : file;
Function saveArea
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async saveArea(ctx, userId) {
logger.info('Saving area');
let image = '';
if (ctx.request.files && ctx.request.files.image && ctx.request.files.image.s3Url) {
image = ctx.request.files.image.s3Url;
Identical blocks of code found in 2 locations. Consider refactoring. Open
} else if (ctx.request.body.fields && ctx.request.body.fields.loggedUser) {
ctx.state.loggedUser = JSON.parse(ctx.request.body.fields.loggedUser);
delete ctx.request.body.loggedUser;
}
- 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 60.
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