NodeBB/NodeBB

View on GitHub
src/controllers/authentication.js

Summary

Maintainability
B
4 hrs
Test Coverage

Function registerComplete has a Cognitive Complexity of 19 (exceeds 10 allowed). Consider refactoring.
Open

authenticationController.registerComplete = async function (req, res) {
    try {
        // For the interstitials that respond, execute the callback with the form body
        const data = await user.interstitials.get(req, req.session.registration);
        const callbacks = data.interstitials.reduce((memo, cur) => {
Severity: Minor
Found in src/controllers/authentication.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 localLogin has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

authenticationController.localLogin = async function (req, username, password, next) {
    if (!username) {
        return next(new Error('[[error:invalid-username]]'));
    }

Severity: Minor
Found in src/controllers/authentication.js - About 35 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 register has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

authenticationController.register = async function (req, res) {
    const registrationType = meta.config.registrationType || 'normal';

    if (registrationType === 'disabled') {
        return res.sendStatus(403);
Severity: Minor
Found in src/controllers/authentication.js - About 35 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 next(new Error('[[error:invalid-login-credentials]]'));
Severity: Major
Found in src/controllers/authentication.js - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

                return next(new Error('[[error:local-login-disabled]]'));
    Severity: Major
    Found in src/controllers/authentication.js - About 30 mins to fix

      Function login has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
      Open

      authenticationController.login = async (req, res, next) => {
          let { strategy } = await plugins.hooks.fire('filter:login.override', { req, strategy: 'local' });
          if (!passport._strategy(strategy)) {
              winston.error(`[auth/override] Requested login strategy "${strategy}" not found, reverting back to local login strategy.`);
              strategy = 'local';
      Severity: Minor
      Found in src/controllers/authentication.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

      There are no issues that match your filters.

      Category
      Status