pinclub/pinclub

View on GitHub
api/v2/topic.js

Summary

Maintainability
F
1 wk
Test Coverage

Function index has 98 lines of code (exceeds 25 allowed). Consider refactoring.
Open

var index = function (req, res, next) {
    var type = req.query.type || 'text';
    var page = parseInt(req.query.page, 10) || 1;
    page = page > 0 ? page : 1;
    var forum = req.query.forum;
Severity: Major
Found in api/v2/topic.js - About 3 hrs to fix

    Function show has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    var show = function (req, res, next) {
        var topicId = String(req.params.id);
    
        var mdrender = req.query.mdrender === 'false' ? false : true;
        var ep = new EventProxy();
    Severity: Minor
    Found in api/v2/topic.js - About 1 hr to fix

      Function update has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      exports.update = function (req, res, next) {
          var topic_id = _.trim(req.body.topic_id);
          var title = _.trim(req.body.title);
          var forum = _.trim(req.body.forum);
          var content = _.trim(req.body.content);
      Severity: Minor
      Found in api/v2/topic.js - About 1 hr to fix

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

        var index = function (req, res, next) {
            var type = req.query.type || 'text';
            var page = parseInt(req.query.page, 10) || 1;
            page = page > 0 ? page : 1;
            var forum = req.query.forum;
        Severity: Minor
        Found in api/v2/topic.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 create has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

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

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

          var create = function (req, res, next) {
              var title = validator.trim(req.body.title || '');
              var forum = validator.trim(req.body.forum);
              var content = validator.trim(req.body.content || '');
          
          
          Severity: Minor
          Found in api/v2/topic.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

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

          exports.update = function (req, res, next) {
              var topic_id = _.trim(req.body.topic_id);
              var title = _.trim(req.body.title);
              var forum = _.trim(req.body.forum);
              var content = _.trim(req.body.content);
          Severity: Major
          Found in api/v2/topic.js and 1 other location - About 2 days to fix
          api/v1/topic.js on lines 223..274

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

          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

              TopicProxy.newAndSave(title, content, forum, req.user.id, client_info, function (err, topic) {
                  if (err) {
                      return next(err);
                  }
          
          
          Severity: Major
          Found in api/v2/topic.js and 1 other location - About 1 day to fix
          api/v1/topic.js on lines 194..218

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

          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

                  topic.replies = replies.map(function (reply) {
                      if (mdrender) {
                          reply.content = renderHelper.markdown(at.linkUsers(reply.content));
                      }
                      reply.author = _.pick(reply.author, ['loginname', 'avatar_url']);
          Severity: Major
          Found in api/v2/topic.js and 1 other location - About 1 day to fix
          api/v1/topic.js on lines 134..149

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

          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 (title === '') {
                  editError = '标题不能为空';
              } else if (title.length < 5 || title.length > 100) {
                  editError = '标题字数太多或太少';
              } else if (!forum) {
          Severity: Major
          Found in api/v2/topic.js and 1 other location - About 2 hrs to fix
          controllers/topic.js on lines 138..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 91.

          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

              if (forum && forum !== 'all') {
                  if (forum === 'good') {
                      query.good = true;
                  } else {
                      query.forum = forum;
          Severity: Major
          Found in api/v2/topic.js and 1 other location - About 1 hr to fix
          api/v1/topic.js on lines 66..74

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

          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

              if (!req.user) {
                  ep.emitLater('is_collect', null);
              } else {
                  TopicCollect.getTopicCollect(req.user._id, topicId, ep.done('is_collect'));
              }
          Severity: Major
          Found in api/v2/topic.js and 1 other location - About 1 hr to fix
          api/v1/topic.js on lines 155..159

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

          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

                      liked_t_ids.forEach(function(lti){
                          let tid = lti.toString();
                          if (topic.id === tid) {
                              structedTopic.liked = true;
                          }
          Severity: Major
          Found in api/v2/topic.js and 1 other location - About 1 hr to fix
          api/v2/image.js on lines 90..95

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

          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

              ep.all('full_topic', 'is_collect', function (full_topic, is_collect) {
                  full_topic.is_collect = !!is_collect;
          
                  res.send({success: true, data: full_topic});
              });
          Severity: Major
          Found in api/v2/topic.js and 1 other location - About 1 hr to fix
          api/v1/topic.js on lines 161..165

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

          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(topicId)) {
                  res.status(400);
                  return res.send({success: false, error_msg: '不是有效的话题id'});
              }
          Severity: Major
          Found in api/v2/topic.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/board.js on lines 230..233
          api/v2/image.js on lines 446..449

          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