gadael/gadael

View on GitHub
schema/Request.js

Summary

Maintainability
F
1 wk
Test Coverage

Function exports has a Cognitive Complexity of 130 (exceeds 5 allowed). Consider refactoring.
Open

exports = module.exports = function(params) {

    const mongoose = params.mongoose;

    var requestSchema = new mongoose.Schema({
Severity: Minor
Found in schema/Request.js - About 2 days 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 526 lines of code (exceeds 25 allowed). Consider refactoring.
Open

exports = module.exports = function(params) {

    const mongoose = params.mongoose;

    var requestSchema = new mongoose.Schema({
Severity: Major
Found in schema/Request.js - About 2 days to fix

    File Request.js has 539 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    'use strict';
    
    
    /**
     * array map function to get Id from the document or ID
    Severity: Major
    Found in schema/Request.js - About 1 day to fix

      Function getDateStatus has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          requestSchema.methods.getDateStatus = function(moment) {
              let requestLog = this.getDateLog();
      
              if (null === requestLog) {
                  return this.status;
      Severity: Minor
      Found in schema/Request.js - About 1 hr to fix

        Function createRecoveryRight has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            requestSchema.methods.createRecoveryRight = function createRecoveryRight() {
        
        
                if (undefined === this.workperiod_recover || 0 === this.workperiod_recover.length) {
                    return Promise.resolve(null);
        Severity: Minor
        Found in schema/Request.js - About 1 hr to fix

          Function accept has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              requestSchema.methods.accept = function accept(approvalStep, user, comment) {
          
                  if (!approvalStep.isApprover(user)) {
                      throw new Error('User not allowed to accept this approval step');
                  }
          Severity: Minor
          Found in schema/Request.js - About 1 hr to fix

            Avoid too many return statements within this function.
            Open

                            return {
                                created: 'accepted',
                                deleted: null
                            };
            Severity: Major
            Found in schema/Request.js - About 30 mins to fix

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

                  requestSchema.methods.getLastApprovalRequestLog = function getLastApprovalRequestLog() {
                      for(var i=this.requestLog.length-1; i>=0; i--) {
                          if (this.requestLog[i].approvalStep !== undefined) {
                              return this.requestLog[i];
                          }
              Severity: Major
              Found in schema/Request.js and 1 other location - About 3 hrs to fix
              schema/Request.js on lines 419..427

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

              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

                  requestSchema.methods.getLastNonApprovalRequestLog = function getLastNonApprovalRequestLog() {
                      for(var i=this.requestLog.length-1; i>=0; i--) {
                          if (this.requestLog[i].approvalStep === undefined) {
                              return this.requestLog[i];
                          }
              Severity: Major
              Found in schema/Request.js and 1 other location - About 3 hrs to fix
              schema/Request.js on lines 404..412

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

              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

                      if (null !== this.status.deleted) {
                          switch(this.status.deleted) {
                              case 'waiting':
                                  return gt.gettext('Waiting deletion approval');
                              case 'accepted':
              Severity: Major
              Found in schema/Request.js and 1 other location - About 2 hrs to fix
              schema/Request.js on lines 374..383

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

              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

                      if (null !== this.status.created) {
                          switch(this.status.created) {
                              case 'waiting':
                                  return gt.gettext('Waiting approval');
                              case 'accepted':
              Severity: Major
              Found in schema/Request.js and 1 other location - About 2 hrs to fix
              schema/Request.js on lines 386..395

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

              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

                  requestSchema.methods.getQuantity = function() {
                      let quantity = 0;
                      this.absence.distribution.forEach(elem => {
                          quantity += elem.quantity;
                      });
              Severity: Major
              Found in schema/Request.js and 1 other location - About 1 hr to fix
              schema/Request.js on lines 232..239

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

              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

                  requestSchema.methods.getConsumedQuantity = function() {
                      let consumed = 0;
                      this.absence.distribution.forEach(elem => {
                          consumed += elem.consumedQuantity;
                      });
              Severity: Major
              Found in schema/Request.js and 1 other location - About 1 hr to fix
              schema/Request.js on lines 218..225

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

              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 3 locations. Consider refactoring.
              Open

                      createdBy: {
                        id: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
                        name: { type: String, required: true }
                      },
              Severity: Major
              Found in schema/Request.js and 2 other locations - About 1 hr to fix
              schema/Invitation.js on lines 10..13
              schema/Lunch.js on lines 6..9

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

              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

                          case 'wf_end':
                              if ('accepted' === this.status.deleted) {
                                  return {
                                      created: null,
                                      deleted: 'accepted'
              Severity: Minor
              Found in schema/Request.js and 1 other location - About 50 mins to fix
              schema/Request.js on lines 285..296

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

              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

                          case 'wf_reject':
                              if ('accepted' === this.status.deleted) {
                                  return {
                                      created: null,
                                      deleted: 'waiting'
              Severity: Minor
              Found in schema/Request.js and 1 other location - About 50 mins to fix
              schema/Request.js on lines 298..309

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

              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

              There are no issues that match your filters.

              Category
              Status