src/controllers/topics.js
Function getTopic
has a Cognitive Complexity of 32 (exceeds 10 allowed). Consider refactoring. Open
Open
topicsController.get = async function getTopic(req, res, next) {
const tid = req.params.topic_id;
if (
(req.params.post_index && !utils.isNumber(req.params.post_index) && req.params.post_index !== 'unread') ||
!utils.isNumber(tid)
- Read upRead up
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 getTopic
has 99 lines of code (exceeds 75 allowed). Consider refactoring. Open
Open
topicsController.get = async function getTopic(req, res, next) {
const tid = req.params.topic_id;
if (
(req.params.post_index && !utils.isNumber(req.params.post_index) && req.params.post_index !== 'unread') ||
!utils.isNumber(tid)
Function addTags
has 80 lines of code (exceeds 75 allowed). Consider refactoring. Open
Open
async function addTags(topicData, req, res, currentPage) {
const postIndex = parseInt(req.params.post_index, 10) || 0;
const postAtIndex = topicData.posts.find(p => parseInt(p.index, 10) === parseInt(Math.max(0, postIndex - 1), 10));
let description = '';
if (postAtIndex && postAtIndex.content) {
Avoid too many return
statements within this function. Open
Open
return helpers.redirect(res, `/topic/${tid}/${req.params.slug}${postIndex > topicData.postcount ? `/${topicData.postcount}` : ''}${generateQueryString(req.query)}`);
Function addTags
has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring. Open
Open
async function addTags(topicData, req, res, currentPage) {
const postIndex = parseInt(req.params.post_index, 10) || 0;
const postAtIndex = topicData.posts.find(p => parseInt(p.index, 10) === parseInt(Math.max(0, postIndex - 1), 10));
let description = '';
if (postAtIndex && postAtIndex.content) {
- Read upRead up
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"