Showing 18 of 18 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
beforeCreate: function(values, queryOptions, callback) {
if (!values.name) {
callback(new Exceptions.InvalidData('You must provide a name'));
} else {
this.find({where: {AccountId: values.AccountId || values.Account, name: values.name}}, queryOptions).then(function(role) {
- 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 141.
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
beforeCreate: function(values, queryOptions, callback) {
if (!values.action) {
callback(new Exceptions.InvalidData('You must provide an action name'));
} else {
this.find({where: {AccountId: values.AccountId || values.Account, action: values.action}}, queryOptions).then(function(permission) {
- 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 141.
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 exports
has 132 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function(async, _, Controller, PermissionService) {
var AccountController = null;
var PermissionController = Controller.extend(
{
Function requiresPermission
has 95 lines of code (exceeds 25 allowed). Consider refactoring. Open
requiresPermission: function(requiredPermissions) {
if (requiredPermissions instanceof Array) {
requiredPermissions = {
all: requiredPermissions
}
Function exports
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function(Promise, Service, RoleModel, PermissionService, underscore, async) {
var debug = require('debug')('cleverstack:services:RoleService');
return Service.extend({
model: RoleModel,
Function exports
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function(Model, config, utils, Exceptions, PermissionModel, UserModel) {
return Model.extend('Role',
{
type : config['clever-roles'].driver || 'ORM',
timeStampable : true,
Function exports
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
module.exports = function(Promise, Service, PermissionModel, async) {
return Service.extend({
model: PermissionModel,
- 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 exports
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function(Promise, Service, PermissionModel, async) {
return Service.extend({
model: PermissionModel,
Function AccountModel afterCreate
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
'AccountModel afterCreate': function(account, values, queryOptions, callback) {
Promise.all([
this.findDefaultRoles(queryOptions),
PermissionService.createAccountDefaultPermissions(account, values, queryOptions)
])
Function exports
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function(Controller, RoleService, PermissionController, AccountController) {
return Controller.extend(
{
service: RoleService,
Function exports
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function(Model, config, async, utils, Exceptions, UserModel, AccountModel) {
return Model.extend('Permission',
{
type : config['clever-roles'].driver || 'ORM',
timeStampable : true,
Function exports
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
module.exports = function(Promise, Service, RoleModel, PermissionService, underscore, async) {
var debug = require('debug')('cleverstack:services:RoleService');
return Service.extend({
model: RoleModel,
- 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 userRoleHasPermission
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
function userRoleHasPermission(permissions, callback) {
var hasPermission = true;
if (!!permissions.length && !req.isAuthenticated()) {
return callback('User is not authenticated!');
Function createAccountDefaultPermissions
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
createAccountDefaultPermissions: function(account, values, queryOptions) {
return new Promise(function(resolve, reject) {
this
.findDefaultPermissions(queryOptions)
.then(this.proxy(function(defaultPermissions) {
Function exports
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
module.exports = function(Model, config, async, utils, Exceptions, UserModel, AccountModel) {
Function exports
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
module.exports = function(Promise, Service, RoleModel, PermissionService, underscore, async) {
Function exports
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
module.exports = function(Model, config, utils, Exceptions, PermissionModel, UserModel) {
Function exports
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
module.exports = function(Controller, RoleService, PermissionController, AccountController) {
return Controller.extend(
{
service: RoleService,
- 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"