holidayextras/jsonapi-server

View on GitHub

Showing 94 of 94 total issues

Function _getPathOperationObject has 136 lines of code (exceeds 25 allowed). Consider refactoring.
Open

swaggerPaths._getPathOperationObject = options => {
  const pathDefinition = {
    tags: [ options.resourceName ],
    description: options.description,
    parameters: [ ],
Severity: Major
Found in lib/swagger/paths.js - About 5 hrs to fix

    Function _getResourceDefinition has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    swaggerPaths._getResourceDefinition = resourceConfig => {
      if (Object.keys(resourceConfig.handlers || { }).length === 0) return undefined
    
      const resourceDefinition = {
        description: resourceConfig.description,
    Severity: Minor
    Found in lib/swagger/resources.js - About 4 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 _arrayToTree has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

    includePP._arrayToTree = (request, includes, filters, callback) => {
      const validationErrors = [ ]
      const tree = {
        _dataItems: null,
        _resourceConfig: [ ].concat(request.resourceConfig)
    Severity: Minor
    Found in lib/postProcessing/include.js - About 4 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 _getResourceDefinition has 106 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    swaggerPaths._getResourceDefinition = resourceConfig => {
      if (Object.keys(resourceConfig.handlers || { }).length === 0) return undefined
    
      const resourceDefinition = {
        description: resourceConfig.description,
    Severity: Major
    Found in lib/swagger/resources.js - About 4 hrs to fix

      Function _getPathOperationObject has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

      swaggerPaths._getPathOperationObject = options => {
        const pathDefinition = {
          tags: [ options.resourceName ],
          description: options.description,
          parameters: [ ],
      Severity: Minor
      Found in lib/swagger/paths.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

      File paths.js has 308 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      'use strict'
      const swaggerPaths = module.exports = { }
      const jsonApi = require('../../')
      const _ = {
        uniq: require('lodash.uniq')
      Severity: Minor
      Found in lib/swagger/paths.js - About 3 hrs to fix

        Function register has 81 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        removeRelationRoute.register = () => {
          router.bindRoute({
            verb: 'delete',
            path: ':type/:id/relationships/:relation'
          }, (request, resourceConfig, res) => {
        Severity: Major
        Found in lib/routes/removeRelation.js - About 3 hrs to fix

          Function _getSwaggerBase has 80 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          swagger._getSwaggerBase = () => {
            const swaggerConfig = jsonApi._apiConfig.swagger || { }
            let basePath, host, protocol
            if (jsonApi._apiConfig.urlPrefixAlias) {
              const urlObj = url.parse(jsonApi._apiConfig.urlPrefixAlias)
          Severity: Major
          Found in lib/swagger/index.js - About 3 hrs to fix

            Function _fillIncludeTree has 78 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            includePP._fillIncludeTree = (includeTree, request, callback) => {
              /** **
              includeTree = {
                _dataItems: [ ],
                _filter: { },
            Severity: Major
            Found in lib/postProcessing/include.js - About 3 hrs to fix

              Function register has 61 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              foreignKeySearchRoute.register = () => {
                router.bindRoute({
                  verb: 'get',
                  path: ':type/relationships/?'
                }, (request, resourceConfig, res) => {
              Severity: Major
              Found in lib/routes/_foreignKeySearch.js - About 2 hrs to fix

                Function register has 59 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                createRoute.register = () => {
                  router.bindRoute({
                    verb: 'post',
                    path: ':type'
                  }, (request, resourceConfig, res) => {
                Severity: Major
                Found in lib/routes/create.js - About 2 hrs to fix

                  Function register has 58 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  relatedRoute.register = () => {
                    router.bindRoute({
                      verb: 'get',
                      path: ':type/:id/:relation'
                    }, (request, resourceConfig, res) => {
                  Severity: Major
                  Found in lib/routes/related.js - About 2 hrs to fix

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

                    includePP._arrayToTree = (request, includes, filters, callback) => {
                      const validationErrors = [ ]
                      const tree = {
                        _dataItems: null,
                        _resourceConfig: [ ].concat(request.resourceConfig)
                    Severity: Major
                    Found in lib/postProcessing/include.js - About 2 hrs to fix

                      Function _addDeepPaths has 54 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      swaggerPaths._addDeepPaths = (paths, resourceName, resourceConfig, relationName, relation) => {
                        const relationType = resourceConfig.attributes[relationName]._settings.__many ? 'many' : 'one'
                      
                        if (resourceConfig.handlers.find) {
                          paths[`/${resourceName}/{id}/${relationName}`] = {
                      Severity: Major
                      Found in lib/swagger/paths.js - About 2 hrs to fix

                        Function register has 54 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        updateRoute.register = () => {
                          router.bindRoute({
                            verb: 'patch',
                            path: ':type/:id'
                          }, (request, resourceConfig, res) => {
                        Severity: Major
                        Found in lib/routes/update.js - About 2 hrs to fix

                          Function register has 54 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          addRelationRoute.register = () => {
                            router.bindRoute({
                              verb: 'post',
                              path: ':type/:id/relationships/:relation'
                            }, (request, resourceConfig, res) => {
                          Severity: Major
                          Found in lib/routes/addRelation.js - About 2 hrs to fix

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

                            responseHelper._generateLink = (item, schemaProperty, linkProperty) => {
                              const link = {
                                meta: {
                                  relation: 'primary',
                                  // type: schemaProperty._settings.__many || schemaProperty._settings.__one,
                            Severity: Major
                            Found in lib/responseHelper.js - About 2 hrs to fix

                              Function register has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                              updateRelationRoute.register = () => {
                                router.bindRoute({
                                  verb: 'patch',
                                  path: ':type/:id/relationships/:relation'
                                }, (request, resourceConfig, res) => {
                              Severity: Minor
                              Found in lib/routes/updateRelation.js - About 2 hrs to fix

                                Function register has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                relationshipsRoute.register = () => {
                                  router.bindRoute({
                                    verb: 'get',
                                    path: ':type/:id/relationships/:relation'
                                  }, (request, resourceConfig, res) => {
                                Severity: Minor
                                Found in lib/routes/relationships.js - About 2 hrs to fix

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

                                    if (resourceConfig.handlers.find) {
                                      relationPaths.get = swaggerPaths._getPathOperationObject({
                                        description: `Get ${description}`,
                                        handler: 'find',
                                        resourceName: relation,
                                  Severity: Major
                                  Found in lib/swagger/paths.js and 3 other locations - About 1 hr to fix
                                  lib/swagger/paths.js on lines 122..131
                                  lib/swagger/paths.js on lines 133..142
                                  lib/swagger/paths.js on lines 144..153

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

                                  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

                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language