File GlobalFunctions.php
has 1024 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Global functions used everywhere.
*
* This program is free software; you can redistribute it and/or modify
Function wfArrayToCgi
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
function wfArrayToCgi( $array1, $array2 = null, $prefix = '' ) {
if ( $array2 !== null ) {
$array1 += $array2;
}
- 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 wfCgiToArray
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
function wfCgiToArray( $query ) {
if ( isset( $query[0] ) && $query[0] == '?' ) {
$query = substr( $query, 1 );
}
$bits = explode( '&', $query );
- 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 wfEscapeWikiText
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
function wfEscapeWikiText( $input ): string {
global $wgEnableMagicLinks;
static $repl = null, $repl2 = null, $repl3 = null, $repl4 = null;
if ( $repl === null || defined( 'MW_PARSER_TEST' ) || defined( 'MW_PHPUNIT_TEST' ) ) {
// Tests depend upon being able to change $wgEnableMagicLinks, so don't cache
Function wfResetOutputBuffers
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
function wfResetOutputBuffers( $resetGzipEncoding = true ) {
while ( $status = ob_get_status() ) {
if ( isset( $status['flags'] ) ) {
$flags = PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_REMOVABLE;
$deleteable = ( $status['flags'] & $flags ) === $flags;
- 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 wfThumbIsStandard
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
function wfThumbIsStandard( File $file, array $params ) {
global $wgThumbLimits, $wgImageLimits, $wgResponsiveImages;
$multipliers = [ 1 ];
if ( $wgResponsiveImages ) {
- 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 wfMerge
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
function wfMerge(
string $old,
string $mine,
string $yours,
?string &$simplisticMergeAttempt,
Method wfThumbIsStandard
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
function wfThumbIsStandard( File $file, array $params ) {
global $wgThumbLimits, $wgImageLimits, $wgResponsiveImages;
$multipliers = [ 1 ];
if ( $wgResponsiveImages ) {
Function wfRecursiveRemoveDir
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
function wfRecursiveRemoveDir( $dir ) {
// taken from https://www.php.net/manual/en/function.rmdir.php#98622
if ( is_dir( $dir ) ) {
$objects = scandir( $dir );
foreach ( $objects as $object ) {
- 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 wfClientAcceptsGzip
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
function wfClientAcceptsGzip( $force = false ) {
static $result = null;
if ( $result === null || $force ) {
$result = false;
if ( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
- 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 wfEscapeWikiText
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
function wfEscapeWikiText( $input ): string {
global $wgEnableMagicLinks;
static $repl = null, $repl2 = null, $repl3 = null, $repl4 = null;
if ( $repl === null || defined( 'MW_PARSER_TEST' ) || defined( 'MW_PHPUNIT_TEST' ) ) {
// Tests depend upon being able to change $wgEnableMagicLinks, so don't 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
Method wfCgiToArray
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
function wfCgiToArray( $query ) {
if ( isset( $query[0] ) && $query[0] == '?' ) {
$query = substr( $query, 1 );
}
$bits = explode( '&', $query );
Method wfArrayToCgi
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
function wfArrayToCgi( $array1, $array2 = null, $prefix = '' ) {
if ( $array2 !== null ) {
$array1 += $array2;
}
Function wfArrayDiff2
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
function wfArrayDiff2( $arr1, $arr2 ) {
/**
* @param string|array $a
* @param string|array $b
*/
- 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 wfArrayDiff2
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
function wfArrayDiff2( $arr1, $arr2 ) {
/**
* @param string|array $a
* @param string|array $b
*/
Method wfGetLangObj
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
function wfGetLangObj( $langcode = false ) {
wfDeprecated( __FUNCTION__, '1.41' );
# Identify which language to get or create a language object for.
# Using is_object here due to Stub objects.
if ( is_object( $langcode ) ) {
Function wfAppendQuery
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
function wfAppendQuery( $url, $query ) {
if ( is_array( $query ) ) {
$query = wfArrayToCgi( $query );
}
if ( $query != '' ) {
- 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 wfShellExec
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function wfShellExec( $cmd, &$retval = null, $environ = [],
$limits = [], $options = []
Method wfMerge
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
string $old,
string $mine,
string $yours,
?string &$simplisticMergeAttempt,
string &$mergeLeftovers = null
Function wfObjectToArray
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
function wfObjectToArray( $objOrArray, $recursive = true ) {
$array = [];
if ( is_object( $objOrArray ) ) {
$objOrArray = get_object_vars( $objOrArray );
}
- 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 wfTransactionalTimeLimit
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
function wfTransactionalTimeLimit() {
global $wgTransactionalTimeLimit;
$timeout = RequestTimeout::singleton();
$timeLimit = $timeout->getWallTimeLimit();
- 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 wfMerge
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
function wfMerge(
string $old,
string $mine,
string $yours,
?string &$simplisticMergeAttempt,
- 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;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return $services->getContentLanguage();
Avoid too many return
statements within this method. Open
return array_udiff( $arr1, $arr2, $comparator );
Function wfMsgReplaceArgs
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
function wfMsgReplaceArgs( $message, $args ) {
# Fix windows line-endings
# Some messages are split with explode("\n", $msg)
$message = str_replace( "\r", '', $message );
- 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 wfMergeErrorArrays
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
function wfMergeErrorArrays( ...$args ) {
$out = [];
foreach ( $args as $errors ) {
foreach ( $errors as $params ) {
$originalParams = $params;
- 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 wfDebugBacktrace
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
function wfDebugBacktrace( $limit = 0 ) {
static $disabled = null;
if ( $disabled === null ) {
$disabled = !function_exists( 'debug_backtrace' );
- 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
$repl = [
'"' => '"', '&' => '&', "'" => ''', '<' => '<',
'=' => '=', '>' => '>', '[' => '[', ']' => ']',
'{' => '{', '|' => '|', '}' => '}',
';' => ';', // a token inside language converter brackets
- 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 172.
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