Function mock
has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring. Open
function mock (context, router, dataStore) {
router = router || context.router;
dataStore = (dataStore instanceof DataStore) ? dataStore : new MemoryDataStore();
let isDisabled = _.noop;
- 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 mock
has 72 lines of code (exceeds 25 allowed). Consider refactoring. Open
function mock (context, router, dataStore) {
router = router || context.router;
dataStore = (dataStore instanceof DataStore) ? dataStore : new MemoryDataStore();
let isDisabled = _.noop;
Function mockResponseHeaders
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
function mockResponseHeaders (req, res, next) {
if (res.swagger) {
util.debug("Setting %d response headers...", _.keys(res.swagger.headers).length);
if (res.swagger.headers) {
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 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
Avoid deeply nested control flow statements. Open
if (req.method === "POST" || req.method === "PUT") {
res.status(201);
}
else if (req.method === "DELETE" && !responses[0].api.schema) {
res.status(204);
Avoid deeply nested control flow statements. Open
if (req.cookies.swagger === undefined) {
res.cookie("swagger", _.uniqueId("random") + _.random(99999999999.9999));
}
else {
res.cookie("swagger", req.cookies.swagger);
Function mockResponseBody
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
function mockResponseBody (req, res, next) {
if (res.swagger) {
if (res.swagger.isEmpty) {
// There is no response schema, so send an empty response
util.debug("%s %s does not have a response schema. Sending an empty response", req.method, req.path);
- 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 deeply nested control flow statements. Open
if (_.isDate(sample)) {
res.set(name, util.rfc1123(sample));
}
else {
res.set(name, _(sample).toString());
Function setContentType
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
function setContentType (req, res, supported, excluded) {
// Get the MIME types that this operation produces
let produces = req.swagger.operation.produces || req.swagger.api.produces || [];
if (produces.length === 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"