CleverStack/clever-roles

View on GitHub

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) {
Severity: Major
Found in models/RoleModel.js and 1 other location - About 5 hrs to fix
models/PermissionModel.js on lines 8..20

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

Further Reading

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) {
Severity: Major
Found in models/PermissionModel.js and 1 other location - About 5 hrs to fix
models/RoleModel.js on lines 33..45

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

Further Reading

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(
  {  
Severity: Major
Found in controllers/PermissionController.js - About 5 hrs to fix

    Function requiresPermission has 95 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        requiresPermission: function(requiredPermissions) {
          if (requiredPermissions instanceof Array) {
            requiredPermissions = {
              all: requiredPermissions
            }
    Severity: Major
    Found in controllers/PermissionController.js - About 3 hrs to fix

      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,
      Severity: Major
      Found in services/RoleService.js - About 2 hrs to fix

        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,
        Severity: Major
        Found in models/RoleModel.js - About 2 hrs to fix

          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,
          
          
          Severity: Minor
          Found in services/PermissionService.js - About 2 hrs to fix

          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,
          
          
          Severity: Major
          Found in services/PermissionService.js - About 2 hrs to fix

            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)
                  ])
            Severity: Major
            Found in services/RoleService.js - About 2 hrs to fix

              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,
                  
              Severity: Minor
              Found in controllers/RoleController.js - About 1 hr to fix

                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,
                Severity: Minor
                Found in models/PermissionModel.js - About 1 hr to fix

                  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,
                  Severity: Minor
                  Found in services/RoleService.js - About 1 hr to fix

                  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!');
                  Severity: Minor
                  Found in controllers/PermissionController.js - About 1 hr to fix

                    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) {
                    Severity: Minor
                    Found in services/PermissionService.js - About 1 hr to fix

                      Function exports has 7 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                      module.exports = function(Model, config, async, utils, Exceptions, UserModel, AccountModel) {
                      Severity: Major
                      Found in models/PermissionModel.js - About 50 mins to fix

                        Function exports has 6 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        module.exports = function(Promise, Service, RoleModel, PermissionService, underscore, async) {
                        Severity: Minor
                        Found in services/RoleService.js - About 45 mins to fix

                          Function exports has 6 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                          module.exports = function(Model, config, utils, Exceptions, PermissionModel, UserModel) {
                          Severity: Minor
                          Found in models/RoleModel.js - About 45 mins to fix

                            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,
                                
                            Severity: Minor
                            Found in controllers/RoleController.js - About 25 mins to fix

                            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

                            Severity
                            Category
                            Status
                            Source
                            Language