pinclub/pinclub

View on GitHub
api/v2/board.js

Summary

Maintainability
D
2 days
Test Coverage

Function collect has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

var collect = function (req, res, next) {
    var board_id = req.body.board_id;
    if (!validator.isMongoId(board_id)) {
        res.status(500);
        return res.send({success: false, error_msg: '不是有效的board_id'});
Severity: Minor
Found in api/v2/board.js - About 1 hr to fix

    Function create has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    var create = function (req, res, next) {
    
        var title = validator.trim(req.body.title || '');
        var type = validator.trim(req.body.type || 'public');
    
    
    Severity: Minor
    Found in api/v2/board.js - About 1 hr to fix

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

      var decollect = function (req, res, next) {
          var board_id = req.body.board_id;
          if (!validator.isMongoId(board_id)) {
              res.status(500);
              return res.send({success: false, error_msg: '不是有效的board_id'});
      Severity: Minor
      Found in api/v2/board.js - About 1 hr to fix

        Function collectList has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function collectList(req, res, next) {
            var loginname = req.params.loginname;
            var ep        = new EventProxy();
        
            ep.fail(next);
        Severity: Minor
        Found in api/v2/board.js - About 1 hr to fix

          Function index has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          var index = function (req, res, next) {
              var type = req.query.type;
              var currentUser = req.session.user;
              var page = parseInt(req.query.page, 10) || 1;
              page = page > 0 ? page : 1;
          Severity: Minor
          Found in api/v2/board.js - About 25 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

                  ep.all('collected_boards', function (collected_topics) {
          
                      var ids = collected_topics.map(function (doc) {
                          return String(doc.board);
                      });
          Severity: Major
          Found in api/v2/board.js and 1 other location - About 5 hrs to fix
          api/v1/topic_collect.js on lines 23..36

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

          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

                  ep.all('boards', function (boards) {
                      boards = boards.map(function (board) {
                          board.author = _.pick(board.author, ['loginname', 'avatar_url']);
                          return _.pick(board, ['id', 'author', 'tab', 'content', 'title', 'last_reply_at',
                              'good', 'top', 'reply_count', 'visit_count', 'create_at', 'author']);
          Severity: Major
          Found in api/v2/board.js and 1 other location - About 3 hrs to fix
          api/v1/topic_collect.js on lines 38..46

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

          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

          exports.delete = function(req, res, next) {
              var boardId = String(req.params.id);
              BoardProxy.remove(boardId, function (err, result) {
                  if (err) {
                      return next(err);
          Severity: Major
          Found in api/v2/board.js and 1 other location - About 2 hrs to fix
          api/v2/image.js on lines 544..552

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

              if (!validator.isMongoId(boardId)) {
                  res.status(400);
                  return res.send({success: false, error_msg: '不是有效的Board id'});
              }
          Severity: Major
          Found in api/v2/board.js and 9 other locations - About 45 mins to fix
          api/v1/reply.js on lines 24..27
          api/v1/reply.js on lines 84..87
          api/v1/topic.js on lines 114..117
          api/v1/topic_collect.js on lines 55..58
          api/v1/topic_collect.js on lines 103..106
          api/v2/board.js on lines 170..173
          api/v2/board.js on lines 230..233
          api/v2/image.js on lines 446..449
          api/v2/topic.js on lines 193..196

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

              if (!validator.isMongoId(board_id)) {
                  res.status(500);
                  return res.send({success: false, error_msg: '不是有效的board_id'});
              }
          Severity: Major
          Found in api/v2/board.js and 9 other locations - About 45 mins to fix
          api/v1/reply.js on lines 24..27
          api/v1/reply.js on lines 84..87
          api/v1/topic.js on lines 114..117
          api/v1/topic_collect.js on lines 55..58
          api/v1/topic_collect.js on lines 103..106
          api/v2/board.js on lines 63..66
          api/v2/board.js on lines 230..233
          api/v2/image.js on lines 446..449
          api/v2/topic.js on lines 193..196

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

              if (!validator.isMongoId(board_id)) {
                  res.status(500);
                  return res.send({success: false, error_msg: '不是有效的board_id'});
              }
          Severity: Major
          Found in api/v2/board.js and 9 other locations - About 45 mins to fix
          api/v1/reply.js on lines 24..27
          api/v1/reply.js on lines 84..87
          api/v1/topic.js on lines 114..117
          api/v1/topic_collect.js on lines 55..58
          api/v1/topic_collect.js on lines 103..106
          api/v2/board.js on lines 63..66
          api/v2/board.js on lines 170..173
          api/v2/image.js on lines 446..449
          api/v2/topic.js on lines 193..196

          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