File Util.php
has 318 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace CirrusSearch;
use MediaWiki\Context\RequestContext;
Util
has 22 functions (exceeds 20 allowed). Consider refactoring. Open
class Util {
/**
* Cache getDefaultBoostTemplates()
*
* @var array|null boost templates
Method identifyNamespace
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function identifyNamespace( $namespace, $method = 'naive', Language $language = null ) {
static $naive = null;
static $utr30 = null;
$normalizer = null;
Function identifyNamespace
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function identifyNamespace( $namespace, $method = 'naive', Language $language = null ) {
static $naive = null;
static $utr30 = null;
$normalizer = null;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getOnWikiBoostTemplates
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function getOnWikiBoostTemplates( SearchConfig $config ) {
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
$cacheKey = $cache->makeGlobalKey( 'cirrussearch-boost-templates', $config->getWikiId() );
if ( $config->getWikiId() == WikiMap::getCurrentWikiId() ) {
// Local wiki we can fetch boost templates from system
Function looksLikeAutomation
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function looksLikeAutomation( SearchConfig $config, string $ip, array $headers ): bool {
// Is there an http header that can be matched with regex to flag automation,
// such as the user-agent or a flag applied by some infrastructure?
$automationHeaders = $config->get( 'CirrusSearchAutomationHeaderRegexes' ) ?? [];
foreach ( $automationHeaders as $name => $pattern ) {
- 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 setIfDefined
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
array $sourceArray,
$sourceKey,
array &$destArray,
$destKey = null,
$mapFn = null,
Function processSearchRawReturn
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function processSearchRawReturn( $result, WebRequest $request,
CirrusDebugOptions $debugOptions ) {
$output = null;
$header = null;
if ( $debugOptions->getCirrusExplainFormat() !== null ) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method overrideNumeric
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function overrideNumeric( &$dest, $request, $name, $limit = null, $upperLimit = true ) {
Function overrideNumeric
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function overrideNumeric( &$dest, $request, $name, $limit = null, $upperLimit = true ) {
$val = $request->getVal( $name );
if ( $val !== null && is_numeric( $val ) ) {
if ( $limit === null ) {
$dest = $val;
- 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 $nonLocalCache;
Avoid too many return
statements within this method. Open
return [];
Function stripQuestionMarks
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function stripQuestionMarks( $term, $strippingLevel ) {
if ( strpos( $term, 'insource:/' ) === false &&
strpos( $term, 'intitle:/' ) === false &&
!preg_match( '/^[\p{P}\p{Z}]+$/u', $term )
) {
- 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 setIfDefined
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function setIfDefined(
array $sourceArray,
$sourceKey,
array &$destArray,
$destKey = 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 isEmpty
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function isEmpty( $v ) {
return ( is_array( $v ) && count( $v ) === 0 ) ||
( is_object( $v ) && count( (array)$v ) === 0 ) ||
( is_string( $v ) && strlen( $v ) === 0 ) ||
( $v === 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"