pinclub/pinclub

View on GitHub
api/v1/topic.js

Summary

Maintainability
F
6 days
Test Coverage

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/v1/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/v1/topic.js - About 1 hr to fix

      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/v1/topic.js - About 1 hr to fix

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

        var index = function (req, res, next) {
            var page = parseInt(req.query.page, 10) || 1;
            page = page > 0 ? page : 1;
            var forum = req.query.forum;
            var limit = Number(req.query.limit) || config.list_topic_count;
        Severity: Minor
        Found in api/v1/topic.js - About 1 hr to fix

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

          var index = function (req, res, next) {
              var page = parseInt(req.query.page, 10) || 1;
              page = page > 0 ? page : 1;
              var forum = req.query.forum;
              var limit = Number(req.query.limit) || config.list_topic_count;
          Severity: Minor
          Found in api/v1/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 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/v1/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/v1/topic.js and 1 other location - About 2 days to fix
          api/v2/topic.js on lines 307..358

          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/v1/topic.js and 1 other location - About 1 day to fix
          api/v2/topic.js on lines 279..303

          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/v1/topic.js and 1 other location - About 1 day to fix
          api/v2/topic.js on lines 213..228

          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

          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/v1/topic.js and 1 other location - About 1 hr to fix
          api/v2/topic.js on lines 80..88

          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/v1/topic.js and 1 other location - About 1 hr to fix
          api/v2/topic.js on lines 234..238

          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

              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/v1/topic.js and 1 other location - About 1 hr to fix
          api/v2/topic.js on lines 240..244

          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/v1/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_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
          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