Showing 414 of 414 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (restrictions && restrictions.whitelist && restrictions.whitelist.roles && restrictions.whitelist.roles.indexOf(req.user.role) == -1)
return kick();
- 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 64.
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 (defaultValue && opt.setDefaults) {
pathO.options.default = defaultValue;
if (type.type == 'date') {
pathO.options.default = pathO.options.default.toISOString();
}
- 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 64.
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 walkSchema
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
function walkSchema(app, Model, schema, parentName, fromArray, rawPath) {
var modelConfig = utils.getModels()[Model.modelName];
for (var key in schema) {
var field = schema[key];
Function getFileNameFromFile
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
function getFileNameFromFile(outDirectory, sourceFileName, cb) {
var fileName = null;
sourceFileName = sourceFileName.toLowerCase();
if (!fs.existsSync(outDirectory)) {
Function getFileNameFromFile
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
function getFileNameFromFile(outDirectory, sourceFileName, cb) {
var fileName = null;
sourceFileName = sourceFileName.toLowerCase();
if (!fs.existsSync(outDirectory)) {
Function DBConnection
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
var DBConnection = /** @class */ (function () {
function DBConnection(config) {
DBConnection.logger.trace("Creating DBConnection instance");
this.config = config;
this.debug(this.config.env.database.debug || false);
Function getFileNameFromFile
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
function getFileNameFromFile(outDirectory, sourceFileName,cb){
var fileName=null;
sourceFileName=sourceFileName.toLowerCase();
if (!fs.existsSync(outDirectory)){
Function checkRole
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
function checkRole(role) {
return function (req, res, next) {
var injector = require('../../../../');
var config = injector.config;
Function uploadFile
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
function uploadFile(item, cb) {
fs.exists(item.path, function (exists) {
if (exists) {
//TODO pass as setting paramter
if(1==0) {//Get file name as randoom
Function uploadFile
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
function uploadFile(item, cb) {
fs.exists(item.path, function (exists) {
if (exists) {
//TODO pass as setting paramter
if (1 == 0) {//Get file name as randoom
Function endOK
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
function endOK() {
var refConf = confs[refModel.modelName];
if (refConf.search.disable === true) {
res.statusCode = statusCode.UNAUTHORIZED;
Function save
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
function save(doc) {
var defer = Q.defer();
//Create the Model object from the json received
if (Model.injector()._references) {
if (Model.injector()._references.toDB) {
Function expressSetup
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
function expressSetup(app, config) {
app.set('views', FSUtils.join(config.appPath, 'views'));
app.set('view engine', config.application.view_engine || 'ejs');
logger.token('body', function getUrlToken(req) {
return req.__body || "";
Function Logger
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
var Logger = /** @class */ (function () {
function Logger() {
}
/**
* Get a logger to log your application
Function MiddlewareRegistry
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
var MiddlewareRegistry = /** @class */ (function () {
function MiddlewareRegistry(config) {
this._middlewares = {};
this.config = config;
MiddlewareRegistry.logger.trace("Creating MiddlewareRegistry instance");
Function expressSetup
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function expressSetup(app:Express, config:any) {
app.set('views', FSUtils.join(config.appPath, 'views'));
app.set('view engine', config.application.view_engine || 'ejs');
Function clearCache
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
FSUtils.clearCache = function (cfg, relativePath) {
var e_1, _a;
return __awaiter(this, void 0, void 0, function () {
var dirName, baseNameNoExt, globPath, stream, stream_1, stream_1_1, entry, e_1_1;
return __generator(this, function (_b) {
Function doLogin
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
function doLogin(model, cbk) {
if (loginInfo.found == undefined) {
model.findOne(loginCondition, null).lean().exec(function (err, result) {
//var logModels = config.login.model;
if (err) {
Function checkToken
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
exports.checkToken = function (req, res, cb) {
var token = req.params.token;
jwt.verify(token, aconf["token.secret"], function (unauthorized, decoded) {
if (unauthorized) {
if(cb) return cb(false);
Function getImage
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
function getImage(param) {
return function (req, res) {
var conf = param.model.injector();