File LanguageConverter.php
has 773 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
LanguageConverter
has 49 functions (exceeds 20 allowed). Consider refactoring. Open
abstract class LanguageConverter implements ILanguageConverter {
use DeprecationHelper;
/**
* languages supporting variants
Function parseCachedTable
has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring. Open
private function parseCachedTable( $code, $subpage = '', $recursive = true ) {
static $parsed = [];
$key = 'Conversiontable/' . $code;
if ( $subpage ) {
- 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 autoConvert
has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring. Open
public function autoConvert( $text, $toVariant = false ) {
$this->loadTables();
if ( !$toVariant ) {
$toVariant = $this->getPreferredVariant();
- 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 autoConvert
has 90 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function autoConvert( $text, $toVariant = false ) {
$this->loadTables();
if ( !$toVariant ) {
$toVariant = $this->getPreferredVariant();
Method parseCachedTable
has 84 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function parseCachedTable( $code, $subpage = '', $recursive = true ) {
static $parsed = [];
$key = 'Conversiontable/' . $code;
if ( $subpage ) {
Function findVariantLink
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
public function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
# If the article has already existed, there is no need to
# check it again. Otherwise it may cause a fault.
if ( $nt instanceof LinkTarget ) {
$nt = Title::castFromLinkTarget( $nt );
- 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 findVariantLink
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
# If the article has already existed, there is no need to
# check it again. Otherwise it may cause a fault.
if ( $nt instanceof LinkTarget ) {
$nt = Title::castFromLinkTarget( $nt );
Function getHeaderVariant
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
protected function getHeaderVariant() {
global $wgRequest;
if ( $this->mHeaderVariant ) {
return $this->mHeaderVariant;
- 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 recursiveConvertRule
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function recursiveConvertRule( $text, $variant, &$startPos, $depth = 0 ) {
// Quick check (no function calls)
if ( $text[$startPos] !== '-' || $text[$startPos + 1] !== '{' ) {
throw new InvalidArgumentException( __METHOD__ . ': invalid input string' );
}
Function recursiveConvertRule
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
protected function recursiveConvertRule( $text, $variant, &$startPos, $depth = 0 ) {
// Quick check (no function calls)
if ( $text[$startPos] !== '-' || $text[$startPos + 1] !== '{' ) {
throw new InvalidArgumentException( __METHOD__ . ': invalid input string' );
}
- 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 getHeaderVariant
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function getHeaderVariant() {
global $wgRequest;
if ( $this->mHeaderVariant ) {
return $this->mHeaderVariant;
Function applyManualConv
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
protected function applyManualConv( ConverterRule $convRule ) {
// Use syntax -{T|zh-cn:TitleCN; zh-tw:TitleTw}- to custom
// title conversion.
// T26072: $mConvRuleTitle was overwritten by other manual
// rule(s) not for title, this breaks the title conversion.
- 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 recursiveConvertTopLevel
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function recursiveConvertTopLevel( $text, $variant, $depth = 0 ) {
$startPos = 0;
$out = '';
$length = strlen( $text );
$shouldConvert = !$this->guessVariant( $text, $variant );
Function getUserVariant
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
protected function getUserVariant( User $user ) {
// This should only be called within the class after the user is known to be
// safe to load and logged in, but check just in case.
if ( !$user->isSafeToLoad() ) {
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
Function getVarSeparatorPattern
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function getVarSeparatorPattern() {
if ( $this->mVarSeparatorPattern === null ) {
// varsep_pattern for preg_split:
// The text should be split by ";" only if a valid variant
// name exists after the markup.
- 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
Consider simplifying this complex logical expression. Open
if ( $disableLinkConversion ||
( !$ignoreOtherCond &&
( $isredir == 'no'
|| $action == 'edit'
|| $action == 'submit'
Function getPreferredVariant
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getPreferredVariant() {
$req = $this->getURLVariant();
$services = MediaWikiServices::getInstance();
( new HookRunner( $services->getHookContainer() ) )->onGetLangPreferredVariant( $req );
- 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"