mozilla/publish.webmaker.org

View on GitHub
api/classes/prerequisites.js

Summary

Maintainability
C
1 day
Test Coverage

Function confirmRecordExists has 53 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  static confirmRecordExists(model, config) {
    config = config || {};
    const dbKey = config.databaseKey || config.requestKey;
    const requestKey = config.requestKey;

Severity: Major
Found in api/classes/prerequisites.js - About 2 hrs to fix

    Function validateCreationPermission has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      static validateCreationPermission(getUserForModelFn) {
        return {
          method(request, reply) {
            const result = Promise.fromCallback(next => {
              return request.server.methods.user(request.auth.credentials.username, next);
    Severity: Minor
    Found in api/classes/prerequisites.js - About 1 hr to fix

      Function confirmRecordExists has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        static confirmRecordExists(model, config) {
          config = config || {};
          const dbKey = config.databaseKey || config.requestKey;
          const requestKey = config.requestKey;
      
      
      Severity: Minor
      Found in api/classes/prerequisites.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 validateOwnership has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        static validateOwnership(recordsAreNotModels, fetchUser, userIsNotModel) {
          if (recordsAreNotModels && typeof fetchUser !== `function`) {
            throw new Error(`fetchUser needs to be a function provided if recordsAreNotModels is set to true`);
          }
      
      
      Severity: Minor
      Found in api/classes/prerequisites.js - About 1 hr to fix

        Function method has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              method(request, reply) {
                const result = Promise.fromCallback(next => {
                  return request.server.methods.user(request.auth.credentials.username, next);
                })
                .then(function(user) {
        Severity: Minor
        Found in api/classes/prerequisites.js - About 1 hr to fix

          Function validateOwnership has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

            static validateOwnership(recordsAreNotModels, fetchUser, userIsNotModel) {
              if (recordsAreNotModels && typeof fetchUser !== `function`) {
                throw new Error(`fetchUser needs to be a function provided if recordsAreNotModels is set to true`);
              }
          
          
          Severity: Minor
          Found in api/classes/prerequisites.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 method has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                method(request, reply) {
                  const records = request.pre.records;
                  const resource = recordsAreNotModels ? records[0] : records.models[0];
                  const authenticatedUser = request.pre.user;
          
          
          Severity: Minor
          Found in api/classes/prerequisites.js - About 1 hr to fix

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

              static validateCreationPermission(getUserForModelFn) {
                return {
                  method(request, reply) {
                    const result = Promise.fromCallback(next => {
                      return request.server.methods.user(request.auth.credentials.username, next);
            Severity: Minor
            Found in api/classes/prerequisites.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

            There are no issues that match your filters.

            Category
            Status