File CoreParserFunctions.php
has 1027 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Parser functions provided by MediaWiki core
*
* This program is free software; you can redistribute it and/or modify
CoreParserFunctions
has 83 functions (exceeds 20 allowed). Consider refactoring. Open
class CoreParserFunctions {
/** @var int Assume that no output will later be saved this many seconds after parsing */
private const MAX_TTS = 900;
/**
Method register
has 72 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function register( Parser $parser, ServiceOptions $options ) {
$options->assertRequiredOptions( self::REGISTER_OPTIONS );
$allowDisplayTitle = $options->get( MainConfigNames::AllowDisplayTitle );
$allowSlowParserFunctions = $options->get( MainConfigNames::AllowSlowParserFunctions );
Function revisionid
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
public static function revisionid( $parser, $title = null ) {
$t = self::makeTitle( $parser, $title );
if ( $t === null || $t->isExternal() ) {
return '';
}
- 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 displaytitle
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
public static function displaytitle( $parser, $text = '', $uarg = '' ) {
$restrictDisplayTitle = MediaWikiServices::getInstance()->getMainConfig()
->get( MainConfigNames::RestrictDisplayTitle );
static $magicWords = 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
Method displaytitle
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function displaytitle( $parser, $text = '', $uarg = '' ) {
$restrictDisplayTitle = MediaWikiServices::getInstance()->getMainConfig()
->get( MainConfigNames::RestrictDisplayTitle );
static $magicWords = null;
Function getCachedRevisionObject
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
private static function getCachedRevisionObject( $parser, $title, $vary ) {
if ( !$title ) {
return 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
Method pagesincategory
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function pagesincategory( $parser, $name = '', $arg1 = '', $arg2 = '' ) {
static $magicWords = null;
if ( $magicWords === null ) {
$magicWords = $parser->getMagicWordFactory()->newArray( [
'pagesincategory_all',
Function tagObj
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public static function tagObj( $parser, $frame, $args ) {
if ( !count( $args ) ) {
return '';
}
$tagName = strtolower( trim( $frame->expand( array_shift( $args ) ) ) );
- 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 getCachedRevisionObject
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function getCachedRevisionObject( $parser, $title, $vary ) {
if ( !$title ) {
return null;
}
Method tagObj
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function tagObj( $parser, $frame, $args ) {
if ( !count( $args ) ) {
return '';
}
$tagName = strtolower( trim( $frame->expand( array_shift( $args ) ) ) );
Method revisionid
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function revisionid( $parser, $title = null ) {
$t = self::makeTitle( $parser, $title );
if ( $t === null || $t->isExternal() ) {
return '';
}
Function filepath
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public static function filepath( $parser, $name = '', $argA = '', $argB = '' ) {
$file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name );
if ( $argA == 'nowiki' ) {
// {{filepath: | option [| size] }}
- 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 pageid
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function pageid( $parser, $title = null ) {
$t = self::makeTitle( $parser, $title );
if ( !$t ) {
return '';
} elseif ( !$t->canExist() || $t->isExternal() ) {
Function getRevisionTimestampSubstring
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private static function getRevisionTimestampSubstring(
Parser $parser,
Title $title,
int $start,
int $len,
- 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 pagesincategory
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function pagesincategory( $parser, $name = '', $arg1 = '', $arg2 = '' ) {
static $magicWords = null;
if ( $magicWords === null ) {
$magicWords = $parser->getMagicWordFactory()->newArray( [
'pagesincategory_all',
- 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 pageid
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function pageid( $parser, $title = null ) {
$t = self::makeTitle( $parser, $title );
if ( !$t ) {
return '';
} elseif ( !$t->canExist() || $t->isExternal() ) {
- 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 getRevisionTimestampSubstring
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Parser $parser,
Title $title,
int $start,
int $len,
int $mtts
Method pad
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
$parser, $string, $length, $padding = '0', $direction = STR_PAD_RIGHT
Function urlFunction
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function urlFunction( $func, $s = '', $arg = null ) {
# Due to order of execution of a lot of bits, the values might be encoded
# before arriving here; if that's true, then the title can't be created
# and the variable will fail. If we can't get a decent title from the first
# attempt, url-decode and try for a second.
- 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 null;
Avoid too many return
statements within this method. Open
return $rev ? $rev->getId() : '';
Avoid too many return
statements within this method. Open
return $id;
Function defaultsort
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function defaultsort( $parser, $text, $uarg = '' ) {
static $magicWords = null;
if ( $magicWords === null ) {
$magicWords = $parser->getMagicWordFactory()->newArray(
[ 'defaultsort_noerror', 'defaultsort_noreplace' ] );
- 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 gender
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function gender( $parser, $username, ...$forms ) {
// Some shortcuts to avoid loading user data unnecessarily
if ( count( $forms ) === 0 ) {
return '';
} elseif ( count( $forms ) === 1 ) {
- 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 formatRaw
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function formatRaw(
$num, $raw, $language, MagicWordFactory $magicWordFactory = null
) {
if ( $raw !== null && $raw !== '' ) {
if ( !$magicWordFactory ) {
- 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
public static function revisionmonth1( $parser, $title = null ) {
$t = self::makeTitle( $parser, $title );
if ( $t === null || $t->isExternal() ) {
return '';
}
- 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 90.
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
public static function revisionday( $parser, $title = null ) {
$t = self::makeTitle( $parser, $title );
if ( $t === null || $t->isExternal() ) {
return '';
}
- 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 90.
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