Showing 68 of 68 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (range) {
if (parsedValue < range.min || parsedValue > range.max) {
throw ono({ status: 400 }, '"%s" is not a valid %s. Must be between %d and %d',
propPath || parsedValue, schema.format, range.min, range.max);
}
- 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 68.
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 (range) {
if (parsedValue < range.min || parsedValue > range.max) {
throw ono({ status: 400 }, '"%s" is not a valid %s. Must be between %d and %d',
propPath || value, schema.format, range.min, range.max);
}
- 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 68.
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 corsHeaders
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
function corsHeaders (req, res, next) {
// Get the default CORS response headers as specified in the Swagger API
let responseHeaders = getResponseHeaders(req);
// Set each CORS header
Function mockResponse
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
function mockResponse (req, res, next) {
if (util.isSwaggerRequest(req) && !isDisabled()) {
let response;
// Is there already a statusCode? (perhaps set by third-party middleware)
Function http401
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
function http401 (req, res, next) {
if (util.isSwaggerRequest(req) && req.swagger.security.length > 0) {
let securityTypes = [];
util.debug("Validating security requirements");
Function parseParameter
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
function parseParameter (param, value, schema) {
if (value === undefined) {
if (param.required) {
// The parameter is required, but was not provided, so throw a 400 error
let errCode = 400;
- 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 requestMetadata
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
function requestMetadata (context, router) {
router = router || context.router;
return [
swaggerMetadata,
- 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 deleteCollection
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
function deleteCollection (req, res, next, dataStore) {
dataStore.getCollection(req.path, (err, resources) => {
if (err) {
next(err);
}
Function sendFile
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
function sendFile (req, res, next, file) {
if (file instanceof Buffer) {
setContentType(req, res, ["application/octet-stream", "*/*"]);
// `file` is the file's contents
Function parseFile
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
function parseFile (schema, value, propPath) {
// Handle missing, required, and default
value = getValueToValidate(schema, value);
// Parse the value
- 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 Middleware
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
function Middleware (sharedRouter) {
sharedRouter = util.isExpressRouter(sharedRouter) ? sharedRouter : undefined;
let self = this;
let context = new MiddlewareContext(sharedRouter);
- 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 getResourceNameByName
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
function getResourceNameByName (data, schema) {
/** @name PropertyInfo */
let propInfo = {
name: "",
schema: {
- 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 generateMultipartFormDataMiddleware
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
function generateMultipartFormDataMiddleware (options) {
options.allowAll = options.allowAll === undefined ? true : options.allowAll;
if (options.inMemory && options.storage === undefined) {
options.storage = multer.memoryStorage();
Function getResourceNameByName
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
function getResourceNameByName (data, schema) {
/** @name PropertyInfo */
let propInfo = {
name: "",
schema: {
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (arguments.length === 1 && !util.isExpressRouter(router) && !util.isExpressRoutingOptions(router)) {
// Shift arguments
options = router;
router = sharedRouter;
}
- 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 59.
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 (arguments.length === 1 && !util.isExpressRouter(router) && !util.isExpressRoutingOptions(router)) {
// Shift arguments
options = router;
router = sharedRouter;
}
- 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 59.
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 queryResource
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
function queryResource (req, res, next, dataStore) {
let resource = new Resource(req.path);
dataStore.get(resource, (err, result) => {
if (err) {
Function sampleDate
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
function sampleDate (schema) {
let min, max;
if (schema.minimum !== undefined) {
min = parseInt(new Date(schema.minimum).valueOf()) + (schema.exclusiveMinimum ? 1 : 0);
}
- 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 createResources
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
function createResources (req) {
let resources = [],
body = req.body,
schema = util.getRequestSchema(req.swagger.path, req.swagger.operation);
- 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 http415
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
function http415 (req, res, next) {
if (util.isSwaggerRequest(req)) {
// Only validate the Content-Type if there's body content
if (!_.isEmpty(req.body)) {
// Get the MIME types that this operation consumes
- 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"