bq/corbel-composr

View on GitHub

Showing 59 of 59 total issues

Consider simplifying this complex logical expression.
Open

      if (body instanceof Error && !body.body) {
        // Parse all errors to restify errors
        body = new ComposrError(body.error || body.message, body.errorDescription || body.code || body.stack,
          body.status || body.statusCode || 500)
      }
Severity: Major
Found in src/lib/server.js - About 1 hr to fix

    Function doWork has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    Worker.prototype.doWork = function (ch, msg) {
      if (msg.fields.routingKey === config.get('rabbitmq.event')) {
        var message
        try {
          message = JSON.parse(msg.content.toString('utf8'))
    Severity: Minor
    Found in src/lib/rabbitMQworker.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

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

        hub.on('snippet:upsert', function (domain, id) {
          counterSnippetsUpdated.inc()
          pmx.emit('snippet:upsert', {
            domain: domain,
            id: id
    Severity: Minor
    Found in src/metrics/keymetrics.js and 1 other location - About 50 mins to fix
    src/metrics/keymetrics.js on lines 140..146

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

    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

        hub.on('phrase:upsert', function (domain, id) {
          counterPhrasesUpdated.inc()
          pmx.emit('phrase:upsert', {
            domain: domain,
            id: id
    Severity: Minor
    Found in src/metrics/keymetrics.js and 1 other location - About 50 mins to fix
    src/metrics/keymetrics.js on lines 132..138

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

    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

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

    module.exports = function () {
      return function tokenObjectHook (req, res, next) {
        var authHeader = req.header('Authorization') || ''
    
        if (!authHeader) {
    Severity: Minor
    Found in src/lib/phraseHooks/tokenObjectHook.js - About 45 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 validateQueryParams has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    function validateQueryParams (schema, items) {
      if (schema && items) {
        // We need sanitize to convert request strings to raml types
        var sanitizeItems = sanitizeRaml(schema)
        var validateItems = validateRaml(schema)
    Severity: Minor
    Found in src/lib/phraseHooks/validateHook.js - About 45 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 add has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    function add (path, verb, authorization, version, data, options) {
    Severity: Minor
    Found in src/lib/modules/cache.js - About 45 mins to fix

      Function remove has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      function remove (path, verb, authorization, version, domain, options) {
      Severity: Minor
      Found in src/lib/modules/cache.js - About 45 mins to fix

        Function authUser has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        module.exports.authUser = function () {
          return function authUser (req, res, next) {
            if (!req.tokenObject) {
              logger.debug('[CorbelAuthHook]', 'Missing token')
              return next(new ComposrError('error:unauthorized', 'Authorization missing', 401))
        Severity: Minor
        Found in src/lib/phraseHooks/corbelAuthHook.js - About 45 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 strip has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        function strip (path) {
          var cur
          var next
          var str = ''
        
        
        Severity: Minor
        Found in src/utils/prePath.js - About 45 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

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

          server.router.routes.POST.forEach(
            function (value) {
              logger.info(value.spec.path)
            }
          )
        Severity: Minor
        Found in src/lib/router.js and 2 other locations - About 40 mins to fix
        src/lib/router.js on lines 209..213
        src/lib/router.js on lines 215..219

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

        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

          server.router.routes.GET.forEach(
            function (value) {
              logger.info(value.spec.path)
            }
          )
        Severity: Minor
        Found in src/lib/router.js and 2 other locations - About 40 mins to fix
        src/lib/router.js on lines 215..219
        src/lib/router.js on lines 221..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 48.

        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

          server.router.routes.PUT.forEach(
            function (value) {
              logger.info(value.spec.path)
            }
          )
        Severity: Minor
        Found in src/lib/router.js and 2 other locations - About 40 mins to fix
        src/lib/router.js on lines 209..213
        src/lib/router.js on lines 221..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 48.

        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

        Function get has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        function get (path, verb, authorization, version, options) {
        Severity: Minor
        Found in src/lib/modules/cache.js - About 35 mins to fix

          Function getKey has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          function getKey (path, verb, authorization, version, type) {
          Severity: Minor
          Found in src/lib/modules/cache.js - About 35 mins to fix

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

                hub.on('http:status', function (status, url, method) {
                  newrelic.recordCustomEvent('http:status', {
                    url: url,
                    status: status,
                    method: method
            Severity: Minor
            Found in src/metrics/newrelic.js and 1 other location - About 35 mins to fix
            src/metrics/keymetrics.js on lines 86..92

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

            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

                hub.on('http:status', function (status, url, method) {
                  pmx.emit('http:status', {
                    url: url,
                    status: status,
                    method: method
            Severity: Minor
            Found in src/metrics/keymetrics.js and 1 other location - About 35 mins to fix
            src/metrics/newrelic.js on lines 70..76

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

            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

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

            module.exports = function (phraseModel, verb) {
              if (engine.services.redis) {
                return function cacheHook (req, res, next) {
                  var path = req.getHref()
            
            
            Severity: Minor
            Found in src/lib/phraseHooks/cacheHook.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 getIdentifier has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            function getIdentifier (tokenObject, maybeType) {
              var type = maybeType || USER_CACHE_TYPE
              var identifier = 'no-token'
            
              if (tokenObject && type !== ANONYMOUS_CACHE_TYPE) {
            Severity: Minor
            Found in src/lib/modules/cache.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

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

            Worker.prototype._removeSnippet = function (domain, id) {
              this.engine.composr.Snippet.unregister(domain, id)
            }
            Severity: Minor
            Found in src/lib/rabbitMQworker.js and 1 other location - About 30 mins to fix
            src/lib/rabbitMQworker.js on lines 63..65

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

            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