File Message.php
has 663 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
Message
has 69 functions (exceeds 20 allowed). Consider refactoring. Open
class Message implements MessageSpecifier, Serializable {
/** Use message text as-is */
public const FORMAT_PLAIN = 'plain';
/** Use normal wikitext -> HTML parsing (the result will be wrapped in a block-level HTML tag) */
public const FORMAT_BLOCK_PARSE = 'block-parse';
Function extractParam
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
protected function extractParam( $param, $format ) {
if ( is_array( $param ) ) {
if ( isset( $param['raw'] ) ) {
return [ 'after', $param['raw'] ];
} elseif ( isset( $param['num'] ) ) {
- 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 extractParam
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function extractParam( $param, $format ) {
if ( is_array( $param ) ) {
if ( isset( $param['raw'] ) ) {
return [ 'after', $param['raw'] ];
} elseif ( isset( $param['num'] ) ) {
Function format
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private function format( string $format ): string {
$string = $this->fetchMessage();
if ( $string === false ) {
// Err on the side of safety, ensure that the output
- 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 params
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function params( ...$args ) {
// If $args has only one entry and it's an array, then it's either a
// non-varargs call or it happens to be a call with just a single
// "special" parameter. Since the "special" parameters don't have any
// numeric keys, we'll test that to differentiate the cases.
- 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 format
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function format( string $format ): string {
$string = $this->fetchMessage();
if ( $string === false ) {
// Err on the side of safety, ensure that the output
Method formatListParam
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function formatListParam( array $params, $listType, $format ) {
if ( !isset( self::$listTypeMap[$listType] ) ) {
$warning = 'Invalid list type for message "' . $this->getKey() . '": '
. htmlspecialchars( $listType )
. ' (params are ' . htmlspecialchars( serialize( $params ) ) . ')';
Function fetchMessage
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected function fetchMessage() {
if ( $this->message === null ) {
$cache = MediaWikiServices::getInstance()->getMessageCache();
foreach ( $this->keysToTry as $key ) {
- 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 replaceParameters
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected function replaceParameters( $message, $type, $format ) {
// A temporary marker for $1 parameters that is only valid
// in non-attribute contexts. However if the entire message is escaped
// then we don't want to use it because it will be mangled in all contexts
// and its unnecessary as ->escaped() messages aren't html.
- 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 __construct
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function __construct( $key, $params = [], Language $language = null ) {
if ( $key instanceof MessageSpecifier ) {
if ( $params ) {
throw new InvalidArgumentException(
'$params must be empty if $key is a MessageSpecifier'
- 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 inLanguage
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function inLanguage( $lang ) {
$previousLanguage = $this->language;
if ( $lang instanceof Language ) {
$this->language = $lang;
- 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 [ 'before', $obj->__toString() ];
Avoid too many return
statements within this method. Open
return [ 'before', $this->getLanguage()->time( $param['time'] ) ];
Avoid too many return
statements within this method. Open
return [ 'before', $this->getLanguage()->getGroupName( $param['group'] ) ];
Avoid too many return
statements within this method. Open
return [ 'before', $param ];
Avoid too many return
statements within this method. Open
return [
'before',
$this->getLanguage()->getGroupMemberName( $obj->getGroup(), $obj->getMember() )
];
Avoid too many return
statements within this method. Open
return [ 'after', $this->formatPlaintext( $param['plaintext'], $format ) ];
Avoid too many return
statements within this method. Open
return [ 'before', $this->getLanguage()->timeanddate( $param['datetime'] ) ];
Avoid too many return
statements within this method. Open
return $this->formatListParam( $param['list'], $param['type'], $format );
Avoid too many return
statements within this method. Open
return [ 'before', $this->getLanguage()->formatTimePeriod( $param['period'] ) ];
Avoid too many return
statements within this method. Open
return [ 'before', '[INVALID]' ];
Avoid too many return
statements within this method. Open
return [ 'after', $msg->format( $format ) ];
Avoid too many return
statements within this method. Open
return [ 'before', $this->getLanguage()->date( $param['date'] ) ];
Avoid too many return
statements within this method. Open
return [ 'before', $this->getLanguage()->formatSize( $param['size'] ) ];
Avoid too many return
statements within this method. Open
return [ 'before', $this->getLanguage()->formatBitrate( $param['bitrate'] ) ];