notduncansmith/summit

View on GitHub
lib/collection/user.js

Summary

Maintainability
F
4 days
Test Coverage

File user.js has 372 lines of code (exceeds 250 allowed). Consider refactoring.
Open

var bcrypt = require('bcrypt')
  , Item = require('./item')
  , _ = require('lodash')
  , Promise = require('bluebird')
  , crypto = require('crypto')
Severity: Minor
Found in lib/collection/user.js - About 4 hrs to fix

    Function validate has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    UserCollection.prototype.validate = function (user) {
      var services = ['password', 'facebook', 'twitter']
        , identifiers = ['email', 'facebookId', 'twitterId', 'username']
        , userIdentifiers = [];
    
    
    Severity: Minor
    Found in lib/collection/user.js - About 1 hr to fix

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

      function authenticatePassword (data) {
        if (!data.username) {
          throw new Error('`username` is required for password authenticate');
        }
      
      
      Severity: Minor
      Found in lib/collection/user.js - About 1 hr to fix

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

        UserCollection.prototype.validate = function (user) {
          var services = ['password', 'facebook', 'twitter']
            , identifiers = ['email', 'facebookId', 'twitterId', 'username']
            , userIdentifiers = [];
        
        
        Severity: Minor
        Found in lib/collection/user.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

        function authenticateFacebook (data) {
          var self = this;
        
          if (!data.token) {
            throw new Error('`token` is required for Facebook authentication.');
        Severity: Major
        Found in lib/collection/user.js and 1 other location - About 5 hrs to fix
        lib/collection/user.js on lines 366..388

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

        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

        function authenticateTwitter (data) {
          var self = this;
        
          if (!data.token) {
            throw new Error('`token` is required for Facebook authentication.');
        Severity: Major
        Found in lib/collection/user.js and 1 other location - About 5 hrs to fix
        lib/collection/user.js on lines 342..364

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

        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

        function unsafeFacebookLogin (data) {
          var secret = this.app.env.unsafeLoginSecret
            , token = data.token
            , facebookId = data.facebookId;
        
        
        Severity: Major
        Found in lib/collection/user.js and 1 other location - About 2 hrs to fix
        lib/collection/user.js on lines 390..403

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

        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

        function unsafeTwitterLogin (data) {
          var secret = this.app.env.unsafeLoginSecret
            , token = data.token
            , twitterId = data.twitterId;
        
        
        Severity: Major
        Found in lib/collection/user.js and 1 other location - About 2 hrs to fix
        lib/collection/user.js on lines 405..418

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

        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

          return this.view('byTwitterId', params, opts || {})
          .then(function (results) {
            if (results.length === 0) {
              return false;
            }
        Severity: Major
        Found in lib/collection/user.js and 2 other locations - About 1 hr to fix
        lib/collection/user.js on lines 74..85
        lib/collection/user.js on lines 127..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 71.

        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

          return this.view('byEmail', params, opts || {})
          .then(function (results) {
            if (results.length === 0) {
              return false;
            }
        Severity: Major
        Found in lib/collection/user.js and 2 other locations - About 1 hr to fix
        lib/collection/user.js on lines 101..112
        lib/collection/user.js on lines 127..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 71.

        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

          return this.view('byFacebookId', params, opts || {})
          .then(function (results) {
            if (results.length === 0) {
              return false;
            }
        Severity: Major
        Found in lib/collection/user.js and 2 other locations - About 1 hr to fix
        lib/collection/user.js on lines 74..85
        lib/collection/user.js on lines 101..112

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

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

          byTwitterId: {
            map: function (doc) {
              if (doc.type === '{{name}}' && doc.twitterId) {
                emit(doc.twitterId, doc);
              }
        Severity: Major
        Found in lib/collection/user.js and 9 other locations - About 50 mins to fix
        cms/page.js on lines 23..29
        cms/page.js on lines 30..36
        cms/post.js on lines 22..28
        cms/post.js on lines 29..35
        cms/post.js on lines 36..42
        lib/collection/group.js on lines 96..102
        lib/collection/user.js on lines 247..253
        lib/collection/user.js on lines 255..261
        lib/services/mailer.js on lines 16..22

        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

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

        UserCollection.fields = {
          service: 'hidden',
          email: 'email',
          username: 'string',
          firstName: 'string',
        Severity: Minor
        Found in lib/collection/user.js and 1 other location - About 50 mins to fix
        lib/services/user.js on lines 5..16

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

          byFacebookId: {
            map: function (doc) {
              if (doc.type === '{{name}}' && doc.facebookId) {
                emit(doc.facebookId, doc);
              }
        Severity: Major
        Found in lib/collection/user.js and 9 other locations - About 50 mins to fix
        cms/page.js on lines 23..29
        cms/page.js on lines 30..36
        cms/post.js on lines 22..28
        cms/post.js on lines 29..35
        cms/post.js on lines 36..42
        lib/collection/group.js on lines 96..102
        lib/collection/user.js on lines 239..245
        lib/collection/user.js on lines 255..261
        lib/services/mailer.js on lines 16..22

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

          byEmail: {
            map: function (doc) {
              if (doc.type === '{{name}}' && doc.email) {
                emit(doc.email, doc);
              }
        Severity: Major
        Found in lib/collection/user.js and 9 other locations - About 50 mins to fix
        cms/page.js on lines 23..29
        cms/page.js on lines 30..36
        cms/post.js on lines 22..28
        cms/post.js on lines 29..35
        cms/post.js on lines 36..42
        lib/collection/group.js on lines 96..102
        lib/collection/user.js on lines 239..245
        lib/collection/user.js on lines 247..253
        lib/services/mailer.js on lines 16..22

        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

          if (_.isArray(email)) {
            params = {
              keys: _.invoke(email, 'toString'),
              include_docs: (opts && opts.include_docs)
            };
        Severity: Minor
        Found in lib/collection/user.js and 1 other location - About 45 mins to fix
        lib/collection/user.js on lines 94..99

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

        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 (_.isArray(id)) {
            params = {
              keys: _.invoke(id, 'toString'),
              include_docs: (opts && opts.include_docs)
            };
        Severity: Minor
        Found in lib/collection/user.js and 1 other location - About 45 mins to fix
        lib/collection/user.js on lines 67..72

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

        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