File ForumController.php
has 802 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace app\modules\yboard\controllers;
use Yii;
Function actionCreateTopic
has a Cognitive Complexity of 70 (exceeds 5 allowed). Consider refactoring. Open
public function actionCreateTopic()
{
if(!Yii::$app->user->can('app.forum.forum.create-topic'))
throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));
- 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 actionTopic
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
public function actionTopic($id, $nav = null, $postId = null) {
$topic = YBoardTopic::findOne($id);
if($topic === null) {
throw new NotFoundHttpException(YBoard::t('yboard', 'The requested topic does not exist.'));
}
- 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
Method actionTopic
has 92 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function actionTopic($id, $nav = null, $postId = null) {
$topic = YBoardTopic::findOne($id);
if($topic === null) {
throw new NotFoundHttpException(YBoard::t('yboard', 'The requested topic does not exist.'));
}
Method actionCreateTopic
has 92 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function actionCreateTopic()
{
if(!Yii::$app->user->can('app.forum.forum.create-topic'))
throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));
ForumController
has 23 functions (exceeds 20 allowed). Consider refactoring. Open
class ForumController extends \yii\web\Controller
{
public $poll;
public $choiceProvider;
Method sendNotifications
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function sendNotifications($postModel)
{
$query = new \yii\db\Query;
$rows = $query->select('user_id')
->from('YBoardPost')
Function actionUpdate
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function actionUpdate($id) {
$post = YBoardPost::findOne($id);
if($post === null) {
throw new NotFoundException(404, YBoard::t('yboard', 'The requested post does not exist.'));
}
- 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 actionUpdatePoll
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function actionUpdatePoll($id) {
$poll = YBoardPoll::findOne($id);
if($poll === null) {
throw new NotFoundHttpException(YBoard::t('yboard', 'The requested poll does not exist.'));
}
- 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
Method actionQuote
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function actionQuote($id) {
if(!Yii::$app->user->can('app.forum.forum.quote'))
throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));
$quoted = YBoardPost::findOne($id);
Method actionIndex
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function actionIndex()
{
$NumberOfTopics = YBoardSetting::find()->where(['key'=>'latest_topic'])->one();
$NumberOfReplies = YBoardSetting::find()->where(['key'=>'latest_reply'])->one();
Function actionForum
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function actionForum($id) {
$forum = $this->findModel($id);
if(Yii::$app->user->isGuest && $forum->public == 0) {
throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no permission to view requested forum.'));
- 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 actionQuote
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function actionQuote($id) {
if(!Yii::$app->user->can('app.forum.forum.quote'))
throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));
$quoted = YBoardPost::findOne($id);
- 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 actionReply
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function actionReply($id) {
if(!Yii::$app->user->can('app.forum.forum.reply'))
throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));
- 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 forumIsRead
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function forumIsRead($forum_id) {
if(Yii::$app->user->isGuest) {
return false;
} else {
$models = YBoardTopic::find()
- 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
Method actionForum
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function actionForum($id) {
$forum = $this->findModel($id);
if(Yii::$app->user->isGuest && $forum->public == 0) {
throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no permission to view requested forum.'));
Method actionReply
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function actionReply($id) {
if(!Yii::$app->user->can('app.forum.forum.reply'))
throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));
Method actionVote
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function actionVote() {
if(!Yii::$app->user->can('app.forum.forum.vote'))
throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));
$json = [];
Method actionUpdate
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function actionUpdate($id) {
$post = YBoardPost::findOne($id);
if($post === null) {
throw new NotFoundException(404, YBoard::t('yboard', 'The requested post does not exist.'));
}
Function actionVote
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function actionVote() {
if(!Yii::$app->user->can('app.forum.forum.vote'))
throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));
$json = [];
- 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
Method actionUpvote
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function actionUpvote() {
if(!Yii::$app->user->can('app.forum.forum.upvote'))
throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));
$json = [];
Method actionUpdatePoll
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function actionUpdatePoll($id) {
$poll = YBoardPoll::findOne($id);
if($poll === null) {
throw new NotFoundHttpException(YBoard::t('yboard', 'The requested poll does not exist.'));
}
Function topicIsRead
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function topicIsRead($topic_id) {
if(Yii::$app->user->isGuest) {
return false;
} else {
$topicLog = YBoardLogTopic::findOne(['member_id'=>Yii::$app->user->id, 'topic_id'=>$topic_id]);
- 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 sendNotifications
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function sendNotifications($postModel)
{
$query = new \yii\db\Query;
$rows = $query->select('user_id')
->from('YBoardPost')
- 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 actionIndex
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function actionIndex()
{
$NumberOfTopics = YBoardSetting::find()->where(['key'=>'latest_topic'])->one();
$NumberOfReplies = YBoardSetting::find()->where(['key'=>'latest_reply'])->one();
- 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
Avoid too many return
statements within this method. Open
return true;
Function topicIcon
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function topicIcon($topic) {
$img = 'topic';
if($this->topicIsRead($topic->id)) {
$img .= '2';
} else {
- 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 actionUpvote
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function actionUpvote() {
if(!Yii::$app->user->can('app.forum.forum.upvote'))
throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));
$json = [];
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if($forum->membergroup_id != 0) {
if(Yii::$app->user->isGuest) {
throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no permission to view requested forum.'));
} elseif(!Yii::$app->user->can('moderator')) {
$groupId = YBoardMember::findOne(Yii::$app->user->id)->group_id;
- Read upRead up
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 114.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if($forum->membergroup_id != 0) {
if(Yii::$app->user->isGuest) {
throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no permission to read requested topic.'));
} elseif(!Yii::$app->user->can('moderator')) {
$groupId = YBoardMember::findOne(Yii::$app->user->id)->group_id;
- Read upRead up
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 114.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if(!Yii::$app->user->isGuest) {
$topicLog = YBoardLogTopic::findOne(['member_id'=>Yii::$app->user->id, 'topic_id'=>$topic->id]);
if($topicLog === null) {
$topicLog = new YBoardLogTopic;
$topicLog->member_id = Yii::$app->user->id;
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
foreach($topics as $topic) {
$topicLog = YBoardLogTopic::findOne(['member_id'=>Yii::$app->user->id, 'topic_id'=>$topic->id]);
if($topicLog === null) {
$topicLog = new YBoardLogTopic;
$topicLog->member_id = Yii::$app->user->id;
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if($post->approved) {
$forum->updateCounters(['num_posts'=>1]);
$topic->updateCounters(['num_replies'=>1]);
$topic->updateAttributes(['last_post_id'=>$post->id]);
- Read upRead up
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 101.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if($post->approved) {
$forum->updateCounters(['num_posts'=>1]);
$topic->updateCounters(['num_replies'=>1]);
- Read upRead up
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 101.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
} else {
$html = Html::button(YBoard::t('yboard', 'Upvote').' <span class="glyphicon glyphicon-chevron-up"></span>', ['class'=>'btn btn-sm btn-default', 'title'=>YBoard::t('yboard', 'Appreciate this post'), 'id'=>'upvote_'.$post_id, 'style'=>'cursor:pointer;', 'onclick'=>'upvotePost(' . $post_id . ',' . $post->user_id . ',"' . $url . '")']);
}
- Read upRead up
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 98.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if($upvoted>0) {
$html = Html::button(YBoard::t('yboard', 'Downvote').' <span class="glyphicon glyphicon-chevron-down"></span>', ['class'=>'btn btn-sm btn-default', 'title'=>YBoard::t('yboard', 'Remove your appreciation'), 'id'=>'upvote_'.$post_id, 'style'=>'cursor:pointer;', 'onclick'=>'upvotePost(' . $post_id . ',' . $post->user_id . ',"' . $url . '")']);
} else {
$html = Html::button(YBoard::t('yboard', 'Upvote').' <span class="glyphicon glyphicon-chevron-up"></span>', ['class'=>'btn btn-sm btn-default', 'title'=>YBoard::t('yboard', 'Appreciate this post'), 'id'=>'upvote_'.$post_id, 'style'=>'cursor:pointer;', 'onclick'=>'upvotePost(' . $post_id . ',' . $post->user_id . ',"' . $url . '")']);
}
- Read upRead up
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 98.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76