File Parser.php
has 4048 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* PHP parser that converts wiki markup to HTML.
*
* This program is free software; you can redistribute it and/or modify
Parser
has 147 functions (exceeds 20 allowed). Consider refactoring. Open
#[\AllowDynamicProperties]
class Parser {
# Flags for Parser::setFunctionHook
public const SFH_NO_HASH = 1;
Function braceSubstitution
has a Cognitive Complexity of 142 (exceeds 5 allowed). Consider refactoring. Open
public function braceSubstitution( array $piece, PPFrame $frame ) {
// Flags
// $text has been filled
$found = false;
- 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 handleInternalLinks2
has a Cognitive Complexity of 118 (exceeds 5 allowed). Consider refactoring. Open
private function handleInternalLinks2( &$s ) {
static $tc = false, $e1, $e1_img;
# the % is needed to support urlencoded titles as well
if ( !$tc ) {
$tc = Title::legalChars() . '#%';
- 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 braceSubstitution
has 310 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function braceSubstitution( array $piece, PPFrame $frame ) {
// Flags
// $text has been filled
$found = false;
Function handleTables
has a Cognitive Complexity of 76 (exceeds 5 allowed). Consider refactoring. Open
private function handleTables( $text ) {
$lines = StringUtils::explode( "\n", $text );
$out = '';
$td_history = []; # Is currently a td tag open?
$last_tag_history = []; # Save history of last lag activated (td, th or caption)
- 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 doQuotes
has a Cognitive Complexity of 76 (exceeds 5 allowed). Consider refactoring. Open
public function doQuotes( $text ) {
$arr = preg_split( "/(''+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE );
$countarr = count( $arr );
if ( $countarr == 1 ) {
return $text;
- 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 makeImage
has a Cognitive Complexity of 69 (exceeds 5 allowed). Consider refactoring. Open
public function makeImage( LinkTarget $link, $options, $holders = false ) {
# Check if the options text is of the form "options|alt text"
# Options are:
# * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
# * left no resizing, just left align. label is used for alt= only
- 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 handleInternalLinks2
has 272 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function handleInternalLinks2( &$s ) {
static $tc = false, $e1, $e1_img;
# the % is needed to support urlencoded titles as well
if ( !$tc ) {
$tc = Title::legalChars() . '#%';
Function finalizeHeadings
has a Cognitive Complexity of 63 (exceeds 5 allowed). Consider refactoring. Open
private function finalizeHeadings( $text, $origText, $isMain = true ) {
# Inhibit editsection links if requested in the page
if ( isset( $this->mDoubleUnderscores['noeditsection'] ) ) {
$maybeShowEditLink = false;
} 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 renderImageGallery
has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring. Open
public function renderImageGallery( $text, array $params ) {
$mode = false;
if ( isset( $params['mode'] ) ) {
$mode = $params['mode'];
}
- 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 finalizeHeadings
has 207 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function finalizeHeadings( $text, $origText, $isMain = true ) {
# Inhibit editsection links if requested in the page
if ( isset( $this->mDoubleUnderscores['noeditsection'] ) ) {
$maybeShowEditLink = false;
} else {
Function statelessFetchTemplate
has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring. Open
public static function statelessFetchTemplate( $page, $parser = false ) {
$title = Title::castFromLinkTarget( $page ); // for compatibility with return type
$text = $skip = false;
$finalTitle = $title;
$deps = [];
- 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 makeImage
has 167 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function makeImage( LinkTarget $link, $options, $holders = false ) {
# Check if the options text is of the form "options|alt text"
# Options are:
# * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
# * left no resizing, just left align. label is used for alt= only
Function extractSections
has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring. Open
private function extractSections( $text, $sectionId, $mode, $newText, ?PageReference $page = null ) {
$magicScopeVariable = $this->lock();
$this->startParse(
$page,
ParserOptions::newFromUser( RequestContext::getMain()->getUser() ),
- 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 handleTables
has 161 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function handleTables( $text ) {
$lines = StringUtils::explode( "\n", $text );
$out = '';
$td_history = []; # Is currently a td tag open?
$last_tag_history = []; # Save history of last lag activated (td, th or caption)
Method doQuotes
has 142 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function doQuotes( $text ) {
$arr = preg_split( "/(''+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE );
$countarr = count( $arr );
if ( $countarr == 1 ) {
return $text;
Method renderImageGallery
has 141 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function renderImageGallery( $text, array $params ) {
$mode = false;
if ( isset( $params['mode'] ) ) {
$mode = $params['mode'];
}
Function cleanUpTocLine
has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring. Open
private function cleanUpTocLine( Node $container ) {
'@phan-var Element|DocumentFragment $container'; // @var Element|DocumentFragment $container
# Strip out HTML
# Allowed tags are:
# * <sup> and <sub> (T10393)
- 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 statelessFetchTemplate
has 120 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function statelessFetchTemplate( $page, $parser = false ) {
$title = Title::castFromLinkTarget( $page ); // for compatibility with return type
$text = $skip = false;
$finalTitle = $title;
$deps = [];
Function extensionSubstitution
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
public function extensionSubstitution( array $params, PPFrame $frame, bool $processNowiki = false ) {
static $errorStr = '<span class="error">';
$name = $frame->expand( $params['name'] );
if ( str_starts_with( $name, $errorStr ) ) {
- 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 callParserFunction
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
public function callParserFunction( PPFrame $frame, $function, array $args = [] ) {
# Case sensitive functions
if ( isset( $this->mFunctionSynonyms[1][$function] ) ) {
$function = $this->mFunctionSynonyms[1][$function];
} 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 maybeMakeExternalImage
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
private function maybeMakeExternalImage( $url ) {
$imagesfrom = $this->mOptions->getAllowExternalImagesFrom();
$imagesexception = (bool)$imagesfrom;
$text = false;
# $imagesfrom could be either a single string or an array of strings, parse out the latter
- 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 extractSections
has 96 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function extractSections( $text, $sectionId, $mode, $newText, ?PageReference $page = null ) {
$magicScopeVariable = $this->lock();
$this->startParse(
$page,
ParserOptions::newFromUser( RequestContext::getMain()->getUser() ),
Method callParserFunction
has 69 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function callParserFunction( PPFrame $frame, $function, array $args = [] ) {
# Case sensitive functions
if ( isset( $this->mFunctionSynonyms[1][$function] ) ) {
$function = $this->mFunctionSynonyms[1][$function];
} else {
Method magicLinkCallback
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function magicLinkCallback( array $m ) {
if ( isset( $m[1] ) && $m[1] !== '' ) {
# Skip anchor
return $m[0];
} elseif ( isset( $m[2] ) && $m[2] !== '' ) {
Method __construct
has 21 arguments (exceeds 4 allowed). Consider refactoring. Open
ServiceOptions $svcOptions,
MagicWordFactory $magicWordFactory,
Language $contLang,
ParserFactory $factory,
UrlUtils $urlUtils,
Method parse
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function parse(
$text, PageReference $page, ParserOptions $options,
$linestart = true, $clearState = true, $revid = null
) {
if ( $clearState ) {
Method extensionSubstitution
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function extensionSubstitution( array $params, PPFrame $frame, bool $processNowiki = false ) {
static $errorStr = '<span class="error">';
$name = $frame->expand( $params['name'] );
if ( str_starts_with( $name, $errorStr ) ) {
Method makeFreeExternalLink
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function makeFreeExternalLink( $url, $numPostProto ) {
$trail = '';
# The characters '<' and '>' (which were escaped by
# internalRemoveHtmlTags()) should not be included in
Function getImageParams
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
private function getImageParams( $handler ) {
if ( $handler ) {
$handlerClass = get_class( $handler );
} else {
$handlerClass = '';
- 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 extractTagsAndParams
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public static function extractTagsAndParams( array $elements, $text, &$matches ) {
static $n = 1;
$stripped = '';
$matches = [];
- 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 magicLinkCallback
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
private function magicLinkCallback( array $m ) {
if ( isset( $m[1] ) && $m[1] !== '' ) {
# Skip anchor
return $m[0];
} elseif ( isset( $m[2] ) && $m[2] !== '' ) {
- 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 normalizeLinkUrl
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function normalizeLinkUrl( $url ) {
# Test for RFC 3986 IPv6 syntax
$scheme = '[a-z][a-z0-9+.-]*:';
$userinfo = '(?:[a-z0-9\-._~!$&\'()*+,;=:]|%[0-9a-f]{2})*';
$ipv6Host = '\\[((?:[0-9a-f:]|%3[0-A]|%[46][1-6])+)\\]';
Method cleanUpTocLine
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function cleanUpTocLine( Node $container ) {
'@phan-var Element|DocumentFragment $container'; // @var Element|DocumentFragment $container
# Strip out HTML
# Allowed tags are:
# * <sup> and <sub> (T10393)
Method handleExternalLinks
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function handleExternalLinks( $text ) {
$bits = preg_split( $this->mExtLinkBracketedRegex, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
// @phan-suppress-next-line PhanTypeComparisonFromArray See phan issue #3161
if ( $bits === false ) {
throw new RuntimeException( "PCRE failure" );
Method makeLimitReport
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function makeLimitReport() {
$maxIncludeSize = $this->mOptions->getMaxIncludeSize();
$cpuTime = $this->mOutput->getTimeProfile( 'cpu' );
if ( $cpuTime !== null ) {
Method extractTagsAndParams
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function extractTagsAndParams( array $elements, $text, &$matches ) {
static $n = 1;
$stripped = '';
$matches = [];
Method getUserSig
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getUserSig( UserIdentity $user, $nickname = false, $fancySig = null ) {
$username = $user->getName();
# If not given, retrieve from the user object.
if ( $nickname === false ) {
Method __construct
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __construct(
ServiceOptions $svcOptions,
MagicWordFactory $magicWordFactory,
Language $contLang,
ParserFactory $factory,
Method interwikiTransclude
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function interwikiTransclude( LinkTarget $link, $action ) {
if ( !$this->svcOptions->get( MainConfigNames::EnableScaryTranscluding ) ) {
return wfMessage( 'scarytranscludedisabled' )->inContentLanguage()->text();
}
Function getUserSig
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function getUserSig( UserIdentity $user, $nickname = false, $fancySig = null ) {
$username = $user->getName();
# If not given, retrieve from the user object.
if ( $nickname === false ) {
- 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 internalParse
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function internalParse( $text, $isMain = true, $frame = false ) {
$origText = $text;
# Hook to suspend the parser in this state
if ( !$this->hookRunner->onParserBeforeInternalParse( $this, $text, $this->mStripState ) ) {
Method stripAltText
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function stripAltText( $caption, $holders ) {
# Strip bad stuff out of the title (tooltip). We can't just use
# replaceLinkHoldersText() here, because if this function is called
# from handleInternalLinks2(), mLinkHolders won't be up-to-date.
if ( $holders ) {
Method maybeMakeExternalImage
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function maybeMakeExternalImage( $url ) {
$imagesfrom = $this->mOptions->getAllowExternalImagesFrom();
$imagesexception = (bool)$imagesfrom;
$text = false;
# $imagesfrom could be either a single string or an array of strings, parse out the latter
Method pstPass2
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function pstPass2( $text, UserIdentity $user ) {
# Note: This is the timestamp saved as hardcoded wikitext to the database, we use
# $this->contLang here in order to give everyone the same signature and use the default one
# rather than the one selected in each user's preferences. (see also T14815)
$ts = $this->mOptions->getTimestamp();
Method handleDoubleUnderscore
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function handleDoubleUnderscore( $text ) {
# The position of __TOC__ needs to be recorded
$mw = $this->magicWordFactory->get( 'toc' );
if ( $mw->match( $text ) ) {
$this->mShowToc = true;
Method getImageParams
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getImageParams( $handler ) {
if ( $handler ) {
$handlerClass = get_class( $handler );
} else {
$handlerClass = '';
Method getFlatSectionInfo
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getFlatSectionInfo( $text ) {
$magicScopeVariable = $this->lock();
$this->startParse(
null,
ParserOptions::newFromUser( RequestContext::getMain()->getUser() ),
Method clearState
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function clearState() {
$this->resetOutput();
$this->mAutonumber = 0;
$this->mLinkHolders = new LinkHolderArray(
$this,
Method internalParseHalfParsed
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function internalParseHalfParsed( $text, $isMain = true, $linestart = true ) {
$text = $this->mStripState->unstripGeneral( $text );
$text = BlockLevelPass::doBlockLevels( $text, $linestart );
Method argSubstitution
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function argSubstitution( array $piece, PPFrame $frame ) {
$error = false;
$parts = $piece['parts'];
$nameWithSpaces = $frame->expand( $piece['title'] );
$argName = trim( $nameWithSpaces );
Function handleExternalLinks
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private function handleExternalLinks( $text ) {
$bits = preg_split( $this->mExtLinkBracketedRegex, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
// @phan-suppress-next-line PhanTypeComparisonFromArray See phan issue #3161
if ( $bits === false ) {
throw new RuntimeException( "PCRE failure" );
- 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 markerSkipCallback
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function markerSkipCallback( $s, callable $callback ) {
$i = 0;
$out = '';
while ( $i < strlen( $s ) ) {
$markerStart = strpos( $s, self::MARKER_PREFIX, $i );
- 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 cleanSig
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function cleanSig( $text, $parsing = false ) {
if ( !$parsing ) {
$magicScopeVariable = $this->lock();
$this->startParse(
$this->mTitle,
Method handleMagicLinks
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function handleMagicLinks( $text ) {
$prots = $this->urlUtils->validAbsoluteProtocols();
$urlChar = self::EXT_LINK_URL_CLASS;
$addr = self::EXT_LINK_ADDR;
$space = self::SPACE_NOT_NL; # non-newline space
Consider simplifying this complex logical expression. Open
if ( isset( $m[1] ) && $m[1] !== '' ) {
# Skip anchor
return $m[0];
} elseif ( isset( $m[2] ) && $m[2] !== '' ) {
# Skip HTML element
Function argSubstitution
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function argSubstitution( array $piece, PPFrame $frame ) {
$error = false;
$parts = $piece['parts'];
$nameWithSpaces = $frame->expand( $piece['title'] );
$argName = trim( $nameWithSpaces );
- 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 localizeTOC
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private static function localizeTOC(
?TOCData $tocData, Language $lang, ?ILanguageConverter $converter
) {
if ( $tocData === null ) {
return; // Nothing to do
- 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 parseLinkParameter
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private function parseLinkParameter( $value ) {
$chars = self::EXT_LINK_URL_CLASS;
$addr = self::EXT_LINK_ADDR;
$prots = $this->urlUtils->validProtocols();
$type = 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 makeFreeExternalLink
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private function makeFreeExternalLink( $url, $numPostProto ) {
$trail = '';
# The characters '<' and '>' (which were escaped by
# internalRemoveHtmlTags()) should not be included in
- 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 parse
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function parse(
$text, PageReference $page, ParserOptions $options,
$linestart = true, $clearState = true, $revid = null
) {
if ( $clearState ) {
- 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 fetchTemplateAndTitle
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function fetchTemplateAndTitle( LinkTarget $link ) {
// Use Title for compatibility with callbacks and return type
$title = Title::newFromLinkTarget( $link );
// Defaults to Parser::statelessFetchTemplate()
- 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 handleDoubleUnderscore
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function handleDoubleUnderscore( $text ) {
# The position of __TOC__ needs to be recorded
$mw = $this->magicWordFactory->get( 'toc' );
if ( $mw->match( $text ) ) {
$this->mShowToc = 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
Method parse
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
$text, PageReference $page, ParserOptions $options,
$linestart = true, $clearState = true, $revid = null
Avoid deeply nested control flow statements. Open
if ( $firstspace == -1 ) {
$firstspace = $i;
}
Consider simplifying this complex logical expression. Open
if ( $text === false && $parts->getLength() > 0
&& ( $this->ot['html']
|| $this->ot['pre']
|| ( $this->ot['wiki'] && $frame->isTemplate() )
)
Method startExternalParse
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function startExternalParse( ?PageReference $page, ParserOptions $options,
$outputType, $clearState = true, $revId = null
Method preprocess
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
$text,
?PageReference $page,
ParserOptions $options,
$revid = null,
$frame = false
Method preSaveTransform
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
$text,
PageReference $page,
UserIdentity $user,
ParserOptions $options,
$clearState = true
Method extractSections
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private function extractSections( $text, $sectionId, $mode, $newText, ?PageReference $page = null ) {
Function getExternalLinkAttribs
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getExternalLinkAttribs( $url ) {
$attribs = [];
$rel = self::getExternalLinkRel( $url, $this->getTitle() ) ?? '';
$target = $this->mOptions->getExternalLinkTarget();
- 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 getRevisionUser
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getRevisionUser(): ?string {
if ( $this->mRevisionUser === null ) {
$revObject = $this->getRevisionRecordObject();
# if this template is subst: the revision id will be blank,
- 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 normalizeLinkUrl
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function normalizeLinkUrl( $url ) {
# Test for RFC 3986 IPv6 syntax
$scheme = '[a-z][a-z0-9+.-]*:';
$userinfo = '(?:[a-z0-9\-._~!$&\'()*+,;=:]|%[0-9a-f]{2})*';
$ipv6Host = '\\[((?:[0-9a-f:]|%3[0-A]|%[46][1-6])+)\\]';
- 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 setFunctionHook
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function setFunctionHook( $id, callable $callback, $flags = 0 ) {
$oldVal = $this->mFunctionHooks[$id][0] ?? null;
$this->mFunctionHooks[$id] = [ $callback, $flags ];
# Add to function 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
Avoid too many return
statements within this method. Open
return $m[0];
Avoid too many return
statements within this method. Open
return $m[0];
Avoid too many return
statements within this method. Open
return $newText;
Avoid too many return
statements within this method. Open
return $marker;
Avoid too many return
statements within this method. Open
return Linker::makeExternalLink(
$url,
"{$keyword} {$id}",
true,
$cssClass,
Avoid too many return
statements within this method. Open
return $this->getLinkRenderer()->makeKnownLink(
SpecialPage::getTitleFor( 'Booksources', $num ),
"ISBN $isbn",
[
'class' => 'internal mw-magiclink-isbn',
Avoid too many return
statements within this method. Open
return $text;
Avoid too many return
statements within this method. Open
return $outText;
Function internalParse
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function internalParse( $text, $isMain = true, $frame = false ) {
$origText = $text;
# Hook to suspend the parser in this state
if ( !$this->hookRunner->onParserBeforeInternalParse( $this, $text, $this->mStripState ) ) {
- 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
} elseif ( $thislen == 3 ) {
// three quotes - open or close bold
if ( $state === 'b' ) {
$output .= '</b>';
$state = '';
- 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 115.
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 ( $thislen == 2 ) {
// two quotes - open or close italics
if ( $state === 'i' ) {
$output .= '</i>';
$state = '';
- 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 115.
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