File ChangeTags.php
has 599 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Recent changes tagging.
*
* This program is free software; you can redistribute it and/or modify
ChangeTags
has 37 functions (exceeds 20 allowed). Consider refactoring. Open
class ChangeTags {
/**
* The tagged edit changes the content model of the page.
*/
public const TAG_CONTENT_MODEL_CHANGE = 'mw-contentmodelchange';
Method updateTagsWithChecks
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function updateTagsWithChecks( $tagsToAdd, $tagsToRemove,
$rc_id, $rev_id, $log_id, $params, string $reason, Authority $performer
) {
if ( !$tagsToAdd && !$tagsToRemove ) {
// no-op, don't bother
Method buildTagFilterSelector
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function buildTagFilterSelector(
$selected = '', $ooui = false, IContextSource $context = null
) {
if ( !$context ) {
$context = RequestContext::getMain();
Method formatSummaryRow
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function formatSummaryRow( $tags, $unused, MessageLocalizer $localizer = null ) {
if ( $tags === '' || $tags === null ) {
return [ '', [] ];
}
if ( !$localizer ) {
Method canDeleteTag
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function canDeleteTag( $tag, Authority $performer = null, int $flags = 0 ) {
$user = null;
$services = MediaWikiServices::getInstance();
if ( $performer !== null ) {
if ( !$performer->isAllowed( 'deletechangetags' ) ) {
Function canUpdateTags
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public static function canUpdateTags(
array $tagsToAdd,
array $tagsToRemove,
Authority $performer = null
) {
- 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 formatSummaryRow
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public static function formatSummaryRow( $tags, $unused, MessageLocalizer $localizer = null ) {
if ( $tags === '' || $tags === null ) {
return [ '', [] ];
}
if ( !$localizer ) {
- 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 canUpdateTags
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function canUpdateTags(
array $tagsToAdd,
array $tagsToRemove,
Authority $performer = null
) {
Method canCreateTag
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function canCreateTag( $tag, Authority $performer = null ) {
$user = null;
$services = MediaWikiServices::getInstance();
if ( $performer !== null ) {
if ( !$performer->isAllowed( 'managechangetags' ) ) {
Function canDeleteTag
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function canDeleteTag( $tag, Authority $performer = null, int $flags = 0 ) {
$user = null;
$services = MediaWikiServices::getInstance();
if ( $performer !== null ) {
if ( !$performer->isAllowed( 'deletechangetags' ) ) {
- 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 updateTagsWithChecks
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function updateTagsWithChecks( $tagsToAdd, $tagsToRemove,
$rc_id, $rev_id, $log_id, $params, string $reason, Authority $performer
) {
if ( !$tagsToAdd && !$tagsToRemove ) {
// no-op, don't bother
- 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 getChangeTagListSummary
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getChangeTagListSummary( MessageLocalizer $localizer, Language $lang ) {
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
return $cache->getWithSetCallback(
$cache->makeKey( 'tags-list-summary', $lang->getCode() ),
WANObjectCache::TTL_DAY,
Method updateTags
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function updateTags( $tagsToAdd, $tagsToRemove, &$rc_id = null,
&$rev_id = null, &$log_id = null, $params = null, RecentChange $rc = null,
UserIdentity $user = null
Method updateTagsWithChecks
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function updateTagsWithChecks( $tagsToAdd, $tagsToRemove,
$rc_id, $rev_id, $log_id, $params, string $reason, Authority $performer
Function canCreateTag
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function canCreateTag( $tag, Authority $performer = null ) {
$user = null;
$services = MediaWikiServices::getInstance();
if ( $performer !== null ) {
if ( !$performer->isAllowed( 'managechangetags' ) ) {
- 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 modifyDisplayQuery
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function modifyDisplayQuery( &$tables, &$fields, &$conds,
&$join_conds, &$options, $filter_tag = '', bool $exclude = false
Function canActivateTag
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function canActivateTag( $tag, Authority $performer = null ) {
if ( $performer !== null ) {
if ( !$performer->isAllowed( 'managechangetags' ) ) {
return Status::newFatal( 'tags-manage-no-permission' );
}
- 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 addTags
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function addTags( $tags, $rc_id = null, $rev_id = null,
$log_id = null, $params = null, RecentChange $rc = null
Method deleteTagWithChecks
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function deleteTagWithChecks( string $tag, string $reason, Authority $performer,
bool $ignoreWarnings = false, array $logEntryTags = []
Method activateTagWithChecks
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function activateTagWithChecks( string $tag, string $reason, Authority $performer,
bool $ignoreWarnings = false, array $logEntryTags = []
Method createTagWithChecks
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function createTagWithChecks( string $tag, string $reason, Authority $performer,
bool $ignoreWarnings = false, array $logEntryTags = []
Method deactivateTagWithChecks
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function deactivateTagWithChecks( string $tag, string $reason, Authority $performer,
bool $ignoreWarnings = false, array $logEntryTags = []
Function canAddTagsAccompanyingChange
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function canAddTagsAccompanyingChange(
array $tags,
Authority $performer = null,
$checkBlock = true
) {
- 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 canDeactivateTag
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function canDeactivateTag( $tag, Authority $performer = null ) {
if ( $performer !== null ) {
if ( !$performer->isAllowed( 'managechangetags' ) ) {
return Status::newFatal( 'tags-manage-no-permission' );
}
- 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 Status::newGood();
Avoid too many return
statements within this method. Open
return Status::newGood( (object)[
'logId' => $logId,
'addedTags' => $tagsAdded,
'removedTags' => $tagsRemoved,
] );
Avoid too many return
statements within this method. Open
return Status::newGood();
Avoid too many return
statements within this method. Open
return $status;
Avoid too many return
statements within this method. Open
return $canCreateResult;
Function getChangeTagList
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function getChangeTagList( MessageLocalizer $localizer, Language $lang ) {
$tags = self::getChangeTagListSummary( $localizer, $lang );
foreach ( $tags as &$tagInfo ) {
if ( $tagInfo['labelMsg'] ) {
// Use localizer with the correct page title to parse plain message from the cache.
- 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 buildTagFilterSelector
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function buildTagFilterSelector(
$selected = '', $ooui = false, IContextSource $context = null
) {
if ( !$context ) {
$context = RequestContext::getMain();
- 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 3 locations. Consider refactoring. Open
public static function deactivateTagWithChecks( string $tag, string $reason, Authority $performer,
bool $ignoreWarnings = false, array $logEntryTags = []
) {
// are we allowed to do this?
$result = self::canDeactivateTag( $tag, $performer );
- 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 155.
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 3 locations. Consider refactoring. Open
public static function activateTagWithChecks( string $tag, string $reason, Authority $performer,
bool $ignoreWarnings = false, array $logEntryTags = []
) {
// are we allowed to do this?
$result = self::canActivateTag( $tag, $performer );
- 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 155.
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 3 locations. Consider refactoring. Open
public static function createTagWithChecks( string $tag, string $reason, Authority $performer,
bool $ignoreWarnings = false, array $logEntryTags = []
) {
// are we allowed to do this?
$result = self::canCreateTag( $tag, $performer );
- 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 155.
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