File Language.php
has 2503 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
Function sprintfDate
has a Cognitive Complexity of 151 (exceeds 5 allowed). Consider refactoring. Open
public function sprintfDate( $format, $ts, DateTimeZone $zone = null, &$ttl = 'unused' ) {
// @phan-suppress-previous-line PhanTypeMismatchDefault Type mismatch on pass-by-ref args
$s = '';
$raw = false;
$roman = 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
Language
has 148 functions (exceeds 20 allowed). Consider refactoring. Open
class Language implements Bcp47Code {
use DebugInfoTrait;
/** @var string */
public $mCode;
Method sprintfDate
has 449 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function sprintfDate( $format, $ts, DateTimeZone $zone = null, &$ttl = 'unused' ) {
// @phan-suppress-previous-line PhanTypeMismatchDefault Type mismatch on pass-by-ref args
$s = '';
$raw = false;
$roman = false;
Function truncateHtml
has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring. Open
public function truncateHtml( $text, $length, $ellipsis = '...' ) {
# Use the localized ellipsis character
if ( $ellipsis == '...' ) {
$ellipsis = $this->msg( 'ellipsis' )->escaped();
}
- 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 formatNumInternal
has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring. Open
private function formatNumInternal(
string $number, bool $noTranslate, bool $noSeparators
): string {
$translateNumerals = $this->config->get( MainConfigNames::TranslateNumerals );
- 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 tsToHebrew
has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring. Open
private static function tsToHebrew( $ts ) {
# Parse date
$year = (int)substr( $ts, 0, 4 );
$month = (int)substr( $ts, 4, 2 );
$day = (int)substr( $ts, 6, 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
Function formatTimePeriod
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
public function formatTimePeriod( $seconds, $format = [] ) {
if ( !is_array( $format ) ) {
$format = [ 'avoid' => $format ]; // For backwards compatibility
}
if ( !isset( $format['avoid'] ) ) {
- 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 tsToHebrew
has 115 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function tsToHebrew( $ts ) {
# Parse date
$year = (int)substr( $ts, 0, 4 );
$month = (int)substr( $ts, 4, 2 );
$day = (int)substr( $ts, 6, 2 );
Method formatNumInternal
has 98 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function formatNumInternal(
string $number, bool $noTranslate, bool $noSeparators
): string {
$translateNumerals = $this->config->get( MainConfigNames::TranslateNumerals );
Method truncateHtml
has 95 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function truncateHtml( $text, $length, $ellipsis = '...' ) {
# Use the localized ellipsis character
if ( $ellipsis == '...' ) {
$ellipsis = $this->msg( 'ellipsis' )->escaped();
}
Function getNamespaceAliases
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
public function getNamespaceAliases() {
if ( $this->namespaceAliases === null ) {
$aliases = $this->localisationCache->getItem( $this->mCode, 'namespaceAliases' );
if ( !$aliases ) {
$aliases = [];
- 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 formatTimePeriod
has 88 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function formatTimePeriod( $seconds, $format = [] ) {
if ( !is_array( $format ) ) {
$format = [ 'avoid' => $format ]; // For backwards compatibility
}
if ( !isset( $format['avoid'] ) ) {
Function hebrewNumeral
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public static function hebrewNumeral( $num ) {
static $table = [
[ '', 'א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ז', 'ח', 'ט', 'י' ],
[ '', 'י', 'כ', 'ל', 'מ', 'נ', 'ס', 'ע', 'פ', 'צ', 'ק' ],
[ '',
- 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 hebrewNumeral
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function hebrewNumeral( $num ) {
static $table = [
[ '', 'א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ז', 'ח', 'ט', 'י' ],
[ '', 'י', 'כ', 'ל', 'מ', 'נ', 'ס', 'ע', 'פ', 'צ', 'ק' ],
[ '',
Function firstChar
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public function firstChar( $s ) {
$firstChar = mb_substr( $s, 0, 1 );
if ( $firstChar === '' || strlen( $firstChar ) != 3 ) {
return $firstChar;
- 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 convertGrammar
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function convertGrammar( $word, $case ) {
$grammarForms = $this->config->get( MainConfigNames::GrammarForms );
if ( isset( $grammarForms[$this->getCode()][$case][$word] ) ) {
return $grammarForms[$this->getCode()][$case][$word];
}
- 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 getNamespaceAliases
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getNamespaceAliases() {
if ( $this->namespaceAliases === null ) {
$aliases = $this->localisationCache->getItem( $this->mCode, 'namespaceAliases' );
if ( !$aliases ) {
$aliases = [];
Function translateBlockExpiry
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function translateBlockExpiry( $str, UserIdentity $user = null, $now = 0 ) {
$duration = $this->getBlockDurations();
$show = array_search( $str, $duration, true );
if ( $show !== false ) {
return trim( $show );
- 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 __construct
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __construct(
$code = null,
NamespaceInfo $namespaceInfo = null,
LocalisationCache $localisationCache = null,
LanguageNameUtils $langNameUtils = null,
Method getHumanTimestampInternal
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getHumanTimestampInternal(
MWTimestamp $ts, MWTimestamp $relativeTo, User $user
) {
$diff = $ts->diff( $relativeTo );
$diffDay = (bool)( (int)$ts->timestamp->format( 'w' ) -
Function getHumanTimestampInternal
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private function getHumanTimestampInternal(
MWTimestamp $ts, MWTimestamp $relativeTo, User $user
) {
$diff = $ts->diff( $relativeTo );
$diffDay = (bool)( (int)$ts->timestamp->format( 'w' ) -
- 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 firstChar
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function firstChar( $s ) {
$firstChar = mb_substr( $s, 0, 1 );
if ( $firstChar === '' || strlen( $firstChar ) != 3 ) {
return $firstChar;
Method truncateInternal
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function truncateInternal(
$string, $length, $ellipsis, $adjustLength, callable $measureLength, callable $getSubstring
) {
# Check if there is no need to truncate
if ( $measureLength( $string ) <= abs( $length ) ) {
Consider simplifying this complex logical expression. Open
if ( $ttl === 'unused' ) {
// No need to calculate the TTL, the caller won't use it anyway.
} elseif ( $usedSecond ) {
$ttl = 1;
} elseif ( $usedMinute ) {
Function truncateInternal
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private function truncateInternal(
$string, $length, $ellipsis, $adjustLength, callable $measureLength, callable $getSubstring
) {
# Check if there is no need to truncate
if ( $measureLength( $string ) <= abs( $length ) ) {
- 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 tsToIranian
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function tsToIranian( $ts ) {
$gy = (int)substr( $ts, 0, 4 ) - 1600;
$gm = (int)substr( $ts, 4, 2 ) - 1;
$gd = (int)substr( $ts, 6, 2 ) - 1;
Method convertGrammar
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function convertGrammar( $word, $case ) {
$grammarForms = $this->config->get( MainConfigNames::GrammarForms );
if ( isset( $grammarForms[$this->getCode()][$case][$word] ) ) {
return $grammarForms[$this->getCode()][$case][$word];
}
Method tsToHijri
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function tsToHijri( $ts ) {
$year = (int)substr( $ts, 0, 4 );
$month = (int)substr( $ts, 4, 2 );
$day = (int)substr( $ts, 6, 2 );
Method getNamespaces
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getNamespaces() {
if ( $this->namespaceNames === null ) {
$metaNamespace = $this->config->get( MainConfigNames::MetaNamespace );
$metaNamespaceTalk = $this->config->get( MainConfigNames::MetaNamespaceTalk );
$extraNamespaces = $this->config->get( MainConfigNames::ExtraNamespaces );
Function tsToYear
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private static function tsToYear( $ts, $cName ) {
$gy = (int)substr( $ts, 0, 4 );
$gm = (int)substr( $ts, 4, 2 );
$gd = (int)substr( $ts, 6, 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 translateBlockExpiry
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function translateBlockExpiry( $str, UserIdentity $user = null, $now = 0 ) {
$duration = $this->getBlockDurations();
$show = array_search( $str, $duration, true );
if ( $show !== false ) {
return trim( $show );
Consider simplifying this complex logical expression. Open
if ( ( $code === 'xi'
|| $code === 'xj'
|| $code === 'xk'
|| $code === 'xm'
|| $code === 'xo'
Method __construct
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
$code = null,
NamespaceInfo $namespaceInfo = null,
LocalisationCache $localisationCache = null,
LanguageNameUtils $langNameUtils = null,
LanguageFallback $langFallback = null,
Consider simplifying this complex logical expression. Open
if ( $c == 0 && $a > 11 && $m >= 0.89772376543210 ) {
$Mar++;
} elseif ( $c == 1 && $a > 6 && $m >= 0.63287037037037 ) {
$Mar += 2;
} elseif ( $c == 2 || $c == 4 || $c == 6 ) {
Function getNamespaces
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function getNamespaces() {
if ( $this->namespaceNames === null ) {
$metaNamespace = $this->config->get( MainConfigNames::MetaNamespace );
$metaNamespaceTalk = $this->config->get( MainConfigNames::MetaNamespaceTalk );
$extraNamespaces = $this->config->get( MainConfigNames::ExtraNamespaces );
- 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 truncate_endBracket
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function truncate_endBracket( &$tag, $tagType, $lastCh, &$openTags ) {
$tag = ltrim( $tag );
if ( $tag != '' ) {
if ( $tagType == 0 && $lastCh != '/' ) {
$openTags[] = $tag; // tag opened (didn't close itself)
- 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 truncateInternal
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
$string, $length, $ellipsis, $adjustLength, callable $measureLength, callable $getSubstring
Consider simplifying this complex logical expression. Open
if (
( $zy > 1582 ) || ( ( $zy == 1582 ) && ( $zm > 10 ) ) ||
( ( $zy == 1582 ) && ( $zm == 10 ) && ( $zd > 14 ) )
) {
$zjd = (int)( ( 1461 * ( $zy + 4800 + (int)( ( $zm - 14 ) / 12 ) ) ) / 4 ) +
Method truncate_skip
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private function truncate_skip( &$ret, $text, $search, $start, $len = null ) {
Function getPluralRuleTypes
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getPluralRuleTypes() {
$pluralRuleTypes =
$this->localisationCache->getItem( strtolower( $this->mCode ), 'pluralRuleTypes' );
if ( !$pluralRuleTypes ) {
$fallbacks = $this->getFallbackLanguages();
- 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 getDateFormatString
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getDateFormatString( $type, $pref ) {
$wasDefault = false;
if ( $pref == 'default' ) {
$wasDefault = true;
$pref = $this->getDefaultDateFormat();
- 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 ucfirst
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function ucfirst( $str ) {
$octetCode = ord( $str );
// See https://en.wikipedia.org/wiki/ASCII#Printable_characters
if ( $octetCode < 96 ) {
// Assume this is an uppercase/uncased ASCII character
- 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 getCompiledPluralRules
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getCompiledPluralRules() {
$pluralRules =
$this->localisationCache->getItem( strtolower( $this->mCode ), 'compiledPluralRules' );
if ( !$pluralRules ) {
$fallbacks = $this->getFallbackLanguages();
- 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 hebrewYearStart
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static function hebrewYearStart( $year ) {
$a = ( 12 * ( $year - 1 ) + 17 ) % 19;
$b = ( $year - 1 ) % 4;
$m = 32.044093161144 + 1.5542417966212 * $a + $b / 4.0 - 0.0031777940220923 * ( $year - 1 );
if ( $m < 0 ) {
- 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 getPluralRules
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getPluralRules() {
$pluralRules =
$this->localisationCache->getItem( strtolower( $this->mCode ), 'pluralRules' );
if ( !$pluralRules ) {
$fallbacks = $this->getFallbackLanguages();
- 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 tsToIranian
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static function tsToIranian( $ts ) {
$gy = (int)substr( $ts, 0, 4 ) - 1600;
$gm = (int)substr( $ts, 4, 2 ) - 1;
$gd = (int)substr( $ts, 6, 2 ) - 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
Avoid too many return
statements within this method. Open
return self::tsToJapaneseGengoCalculate( $gy, 2019, '令和' );
Avoid too many return
statements within this method. Open
return "西暦$gy";
Avoid too many return
statements within this method. Open
return "\u{314A}";
Avoid too many return
statements within this method. Open
return '↑';
Avoid too many return
statements within this method. Open
return "\u{3139}";
Avoid too many return
statements within this method. Open
return "\u{3142}";
Avoid too many return
statements within this method. Open
return "\u{3137}";
Avoid too many return
statements within this method. Open
return "\u{314C}";
Avoid too many return
statements within this method. Open
return $this->userTimeAndDate( $time, $user );
Avoid too many return
statements within this method. Open
return $this->timeanddate( $time );
Avoid too many return
statements within this method. Open
return "\u{3147}";
Avoid too many return
statements within this method. Open
return preg_replace_callback( "/{$validNumberRe}/", function ( $m ) use ( $noTranslate, $noSeparators ) {
return $this->formatNumInternal( $m[0], $noTranslate, $noSeparators );
}, $number );
Avoid too many return
statements within this method. Open
return $str;
Avoid too many return
statements within this method. Open
return "\u{3145}";
Avoid too many return
statements within this method. Open
return '↓';
Avoid too many return
statements within this method. Open
return strtr( $number, [
"\u{200E}" => '', // LRM
"\u{200F}" => '', // RLM
"\u{061C}" => '', // ALM
] );
Avoid too many return
statements within this method. Open
return "\u{314D}";
Avoid too many return
statements within this method. Open
return "\u{3141}";
Avoid too many return
statements within this method. Open
return "\u{3148}";
Avoid too many return
statements within this method. Open
return "\u{314B}";
Avoid too many return
statements within this method. Open
return "\u{314E}";
Function internalUserTimeAndDate
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function internalUserTimeAndDate( $type, $ts, UserIdentity $user, array $options ) {
$ts = wfTimestamp( TS_MW, $ts );
$options += [ 'timecorrection' => true, 'format' => true ];
if ( $options['timecorrection'] !== false ) {
if ( $options['timecorrection'] === true ) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function dateFormat
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function dateFormat( $usePrefs = true ) {
if ( is_bool( $usePrefs ) ) {
if ( $usePrefs ) {
$datePreference = 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
Function handleExplicitPluralForms
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function handleExplicitPluralForms( $count, array $forms ) {
foreach ( $forms as $index => $form ) {
if ( preg_match( '/\d+=/i', $form ) ) {
$pos = strpos( $form, '=' );
if ( substr( $form, 0, $pos ) === (string)$count ) {
- 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 getDurationIntervals
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getDurationIntervals( $seconds, array $chosenIntervals = [] ) {
if ( !$chosenIntervals ) {
$chosenIntervals = [
'millennia',
'centuries',
- 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 tsToJapaneseGengo
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static function tsToJapaneseGengo( $ts ) {
# Nengō dates up to Meiji period.
# Deduct years from the Gregorian calendar
# depending on the nengo periods
# The months and days are identical
- 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 tsToHijri
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static function tsToHijri( $ts ) {
$year = (int)substr( $ts, 0, 4 );
$month = (int)substr( $ts, 4, 2 );
$day = (int)substr( $ts, 6, 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
Similar blocks of code found in 3 locations. Consider refactoring. Open
public function time( $ts, $adj = false, $format = true, $timecorrection = false ) {
$ts = wfTimestamp( TS_MW, $ts );
if ( $adj ) {
$ts = $this->userAdjust( $ts, $timecorrection );
}
- 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 110.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 3 locations. Consider refactoring. Open
public function timeanddate( $ts, $adj = false, $format = true, $timecorrection = false ) {
$ts = wfTimestamp( TS_MW, $ts );
if ( $adj ) {
$ts = $this->userAdjust( $ts, $timecorrection );
}
- 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 110.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 3 locations. Consider refactoring. Open
public function date( $ts, $adj = false, $format = true, $timecorrection = false ) {
$ts = wfTimestamp( TS_MW, $ts );
if ( $adj ) {
$ts = $this->userAdjust( $ts, $timecorrection );
}
- 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 110.
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