mylisabox/trailpack-chatbot

View on GitHub

Showing 14 of 20 total issues

Function _searchMatch has a Cognitive Complexity of 65 (exceeds 5 allowed). Consider refactoring.
Open

  _searchMatch(bot, stateData, lang, userSentence, sentences) {
    let results = null
    if (sentences[lang]) {
      for (let j = 0; j < sentences[lang].length; j++) {
        const sentenceData = sentences[lang][j]
Severity: Minor
Found in api/services/ChatBotService.js - About 1 day 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

File ChatBotService.js has 391 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict'

const Service = require('trails/service')
const _ = require('lodash')

Severity: Minor
Found in api/services/ChatBotService.js - About 5 hrs to fix

    Function interact has 92 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      interact(userId, lang, userSentence, chatBotId) {
        if (!userId && !this.app.config.chatbot.allowAnonymousUsers) {
          return Promise.reject('No user provided')
        }
    
    
    Severity: Major
    Found in api/services/ChatBotService.js - About 3 hrs to fix

      Function _prepareChatBot has 55 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _prepareChatBot(botId, botData) {
          let data
          if (botData.originalData) {
            botData.data.links = botData.originalData.links
            botData.data.freeStates = botData.originalData.freeStates
      Severity: Major
      Found in api/services/ChatBotService.js - About 2 hrs to fix

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

          static schema(app, Sequelize) {
            return {
              name: {
                type: Sequelize.STRING,
                primaryKey: true,
        Severity: Major
        Found in api/models/ChatBot.js - About 2 hrs to fix

          Function _searchMatch has 51 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            _searchMatch(bot, stateData, lang, userSentence, sentences) {
              let results = null
              if (sentences[lang]) {
                for (let j = 0; j < sentences[lang].length; j++) {
                  const sentenceData = sentences[lang][j]
          Severity: Major
          Found in api/services/ChatBotService.js - About 2 hrs to fix

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

              init(initialData) {
                this.botCache = this.app.services.CacheService.getStore('chatbot')
                initialData = _.cloneDeep(initialData)
                this.chatBots = []
                return this._prepareParams().then(() => this.app.orm.ChatBot.findAll({
            Severity: Minor
            Found in api/services/ChatBotService.js - About 1 hr to fix

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

                reloadBots() {
                  return this._prepareParams().then(() => this.app.orm.ChatBot.findAll({
                    where: {
                      enabled: true
                    }
              Severity: Minor
              Found in api/services/ChatBotService.js - About 1 hr to fix

                Function _prepareParam has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  _prepareParam(key, value) {
                    if (Array.isArray(value)) {
                      mapParams[key] = `(${value.join('|')})`
                    }
                    else if (_.isFunction(value)) {
                Severity: Minor
                Found in api/services/ChatBotService.js - About 1 hr to fix

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

                    static schema(app, Sequelize) {
                      return {
                        name: {
                          type: Sequelize.STRING,
                          primaryKey: true,
                  Severity: Minor
                  Found in api/models/ChatBot.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 _prepareParam has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                    _prepareParam(key, value) {
                      if (Array.isArray(value)) {
                        mapParams[key] = `(${value.join('|')})`
                      }
                      else if (_.isFunction(value)) {
                  Severity: Minor
                  Found in api/services/ChatBotService.js - About 55 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 deeply nested control flow statements.
                  Open

                              for (let i = 1; i < matches.length; i++) {
                                let value = matches[i]
                                const type = sentenceData.fields[i - 1]
                                const param = this.app.config.chatbot.params[type]
                                if (type.indexOf('number') !== -1) {
                  Severity: Major
                  Found in api/services/ChatBotService.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                    if (result) {
                                      break
                                    }
                    Severity: Major
                    Found in api/services/ChatBotService.js - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                        if (hook) {
                                          hook(this.app, publicResult).then(resolve).catch(reject)
                                        }
                                        else {
                                          resolve(publicResult)
                      Severity: Major
                      Found in api/services/ChatBotService.js - About 45 mins to fix
                        Severity
                        Category
                        Status
                        Source
                        Language