jaumard/trailpack-passport

View on GitHub

Showing 15 of 15 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

module.exports = class Passport extends Model {

  static config(app, orm) {
    if (app) {
      return require('./' + app.config.database.orm).Passport.config(app, orm)
Severity: Major
Found in api/models/Passport.js and 1 other location - About 4 hrs to fix
api/models/User.js on lines 9..23

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 126.

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

module.exports = class User extends Model {

  static config(app, orm) {
    if (app) {
      return require('./' + app.config.database.orm).User.config(app, orm)
Severity: Major
Found in api/models/User.js and 1 other location - About 4 hrs to fix
api/models/Passport.js on lines 9..23

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 126.

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

module.exports = module.exports = (app) => {
  const passport = app.services.PassportService.passport
  return (req, accessToken, refreshToken, profile, next) => {
    const query = {
      identifier: profile.id,
Severity: Major
Found in api/services/protocols/oauth2.js and 1 other location - About 4 hrs to fix
api/services/protocols/oauth.js on lines 22..37

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 120.

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

module.exports = (app) => {
  const passport = app.services.PassportService.passport
  return (req, token, tokenSecret, profile, next) => {
    const query = {
      identifier: profile.id,
Severity: Major
Found in api/services/protocols/oauth.js and 1 other location - About 4 hrs to fix
api/services/protocols/oauth2.js on lines 23..38

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 120.

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 init has 82 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  init: (app) => {
    const passport = app.services.PassportService.passport
    app.config.web.middlewares.passportInit = passport.initialize()
    app.config.web.middlewares.passportSession = passport.session()

Severity: Major
Found in lib/passports.js - About 3 hrs to fix

    Function callback has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

      callback(req, res, next) {
        const provider = req.params.provider || 'local'
        const action = req.params.action
    
        if (provider === 'local') {
    Severity: Minor
    Found in api/services/PassportService.js - About 3 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 connect has 67 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        passport.connect = function (req, query, profile, next) {
          const user = {}
    
          // Get the authentication provider from the query.
          query.provider = req.params.provider
    Severity: Major
    Found in lib/passports.js - About 2 hrs to fix

      Function callback has 44 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        callback(req, res) {
          this.app.services.PassportService.callback(req, res, (err, user, challenges, statuses) => {
            if (err) {
              if (err.code === 'E_USER_NOT_FOUND') {
                req.err = err
      Severity: Minor
      Found in api/controllers/AuthController.js - About 1 hr to fix

        Function callback has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          callback(req, res, next) {
            const provider = req.params.provider || 'local'
            const action = req.params.action
        
            if (provider === 'local') {
        Severity: Minor
        Found in api/services/PassportService.js - About 1 hr to fix

          Function loadStrategies has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            loadStrategies: (app) => {
              const passport = app.services.PassportService.passport
              _.each(app.config.passport.strategies, (strategiesOptions, name) => {
                  const Strategy = strategiesOptions.strategy
                  const options = _.extend({ passReqToCallback: true }, strategiesOptions.options || {})
          Severity: Minor
          Found in lib/passports.js - About 1 hr to fix

            Function init has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              init: (app) => {
                const passport = app.services.PassportService.passport
                app.config.web.middlewares.passportInit = passport.initialize()
                app.config.web.middlewares.passportSession = passport.session()
            
            
            Severity: Minor
            Found in lib/passports.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 exports has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            module.exports = (bcrypt, passport, next) => {
              if (passport.password) {
                if (next) {
                  bcrypt.hash(passport.password, 10, (err, hash) => {
                    passport.password = hash
            Severity: Minor
            Found in api/models/hashPassword.js - About 45 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

            Function validate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              validate() {
                if (!_.includes(_.keys(this.app.packs), 'express')) {
                  return Promise.reject(new Error('This Trailpack work only for express !'))
                }
            
            
            Severity: Minor
            Found in index.js - About 45 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

            Avoid too many return statements within this function.
            Open

                  return Promise.reject(new Error('You need to change the default token !'))
            Severity: Major
            Found in index.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                  return Promise.all([
                    lib.Validator.validatePassportsConfig(this.app.config.passport)
                  ])
              Severity: Major
              Found in index.js - About 30 mins to fix
                Severity
                Category
                Status
                Source
                Language