File ResourceLoader.php
has 1247 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
ResourceLoader
has 71 functions (exceeds 20 allowed). Consider refactoring. Open
class ResourceLoader implements LoggerAwareInterface {
/** @var int */
public const CACHE_VERSION = 9;
/** @var string JavaScript / CSS pragma to disable minification. * */
public const FILTER_NOMIN = '/*@nomin*/';
Function makeModuleResponse
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
public function makeModuleResponse( Context $context,
array $modules, array $missing = []
) {
if ( $modules === [] && $missing === [] ) {
return <<<MESSAGE
- 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 respond
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
public function respond( Context $context ) {
// Buffer output to catch warnings. Normally we'd use ob_clean() on the
// top-level output buffer to clear warnings, but that breaks when ob_gzhandler
// is used: ob_clean() will clear the GZIP header in that case and it won't come
// back for subsequent output, resulting in invalid GZIP. So we have to wrap
- 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 respond
has 78 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function respond( Context $context ) {
// Buffer output to catch warnings. Normally we'd use ob_clean() on the
// top-level output buffer to clear warnings, but that breaks when ob_gzhandler
// is used: ob_clean() will clear the GZIP header in that case and it won't come
// back for subsequent output, resulting in invalid GZIP. So we have to wrap
Method getOneModuleResponse
has 70 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getOneModuleResponse( Context $context, $name, Module $module ) {
$only = $context->getOnly();
// Important: Do not cache minifications of embedded modules
// This is especially for the private 'user.options' module,
// which varies on every pageview and would explode the cache (T84960)
Method makeModuleResponse
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function makeModuleResponse( Context $context,
array $modules, array $missing = []
) {
if ( $modules === [] && $missing === [] ) {
return <<<MESSAGE
Function getLessCompiler
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public function getLessCompiler( array $vars = [], array $importDirs = [] ) {
global $IP;
// When called from the installer, it is possible that a required PHP extension
// is missing (at least for now; see T49564). If this is the case, throw an
// exception (caught by the installer) to prevent a fatal error later on.
- 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 addOneModuleResponse
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function addOneModuleResponse(
Context $context, MinifierState $minifier, $name, Module $module, &$headers
) {
$only = $context->getOnly();
$debug = (bool)$context->getDebug();
Function saveModuleDependenciesInternal
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function saveModuleDependenciesInternal( $moduleName, $variant, $paths, $priorPaths ) {
$hasPendingUpdate = (bool)$this->depStoreUpdateBuffer;
$entity = "$moduleName|$variant";
if ( array_diff( $paths, $priorPaths ) || array_diff( $priorPaths, $paths ) ) {
- 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 getLessCompiler
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getLessCompiler( array $vars = [], array $importDirs = [] ) {
global $IP;
// When called from the installer, it is possible that a required PHP extension
// is missing (at least for now; see T49564). If this is the case, throw an
// exception (caught by the installer) to prevent a fatal error later on.
Method getSiteConfigSettings
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getSiteConfigSettings(
Context $context, Config $conf
): array {
$services = MediaWikiServices::getInstance();
// Namespace related preparation
Function sendResponseHeaders
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
protected function sendResponseHeaders(
Context $context, $etag, $errors, array $extra = []
): void {
HeaderCallback::warnIfHeadersSent();
- 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 addOneModuleResponse
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
private function addOneModuleResponse(
Context $context, MinifierState $minifier, $name, Module $module, &$headers
) {
$only = $context->getOnly();
$debug = (bool)$context->getDebug();
- 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 addImplementScript
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private function addImplementScript( MinifierState $minifier,
$moduleName, $version, $scripts, $styles, $messages, $templates, $deprecationWarning
) {
$implementKey = "$moduleName@$version";
// Plain functions are used instead of arrow functions to 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 sendResponseHeaders
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function sendResponseHeaders(
Context $context, $etag, $errors, array $extra = []
): void {
HeaderCallback::warnIfHeadersSent();
Method addImplementScript
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function addImplementScript( MinifierState $minifier,
$moduleName, $version, $scripts, $styles, $messages, $templates, $deprecationWarning
) {
$implementKey = "$moduleName@$version";
// Plain functions are used instead of arrow functions to avoid
Function makeCombinedStyles
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public static function makeCombinedStyles( array $stylePairs ) {
$out = [];
foreach ( $stylePairs as $media => $styles ) {
// FileModule::getStyle can return the styles as a string or an
// array of strings. This is to allow separation in the front-end.
- 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 saveModuleDependenciesInternal
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function saveModuleDependenciesInternal( $moduleName, $variant, $paths, $priorPaths ) {
$hasPendingUpdate = (bool)$this->depStoreUpdateBuffer;
$entity = "$moduleName|$variant";
if ( array_diff( $paths, $priorPaths ) || array_diff( $priorPaths, $paths ) ) {
Method preloadModuleInfo
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function preloadModuleInfo( array $moduleNames, Context $context ) {
// Load all tracked indirect file dependencies for the modules
$vary = Module::getVary( $context );
$entitiesByModule = [];
foreach ( $moduleNames as $moduleName ) {
Method makeLoaderQuery
has 10 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function makeLoaderQuery( array $modules, $lang, $skin, $user = null,
$version = null, $debug = Context::DEBUG_OFF, $only = null,
$printable = false, $handheld = null, array $extraQuery = []
Function makeLoaderRegisterScript
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public static function makeLoaderRegisterScript(
Context $context, array $modules
) {
// Optimisation: Transform dependency names into indexes when possible
// to produce smaller output. They are expanded by mw.loader.register on
- 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 filter
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function filter( $filter, $data, array $options = [] ) {
if ( strpos( $data, self::FILTER_NOMIN ) !== false ) {
return $data;
}
Method makeLoaderQuery
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function makeLoaderQuery( array $modules, $lang, $skin, $user = null,
$version = null, $debug = Context::DEBUG_OFF, $only = null,
$printable = false, $handheld = null, array $extraQuery = []
) {
$query = [
Function getOneModuleResponse
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function getOneModuleResponse( Context $context, $name, Module $module ) {
$only = $context->getOnly();
// Important: Do not cache minifications of embedded modules
// This is especially for the private 'user.options' module,
// which varies on every pageview and would explode the cache (T84960)
- 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 addImplementScript
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
private function addImplementScript( MinifierState $minifier,
$moduleName, $version, $scripts, $styles, $messages, $templates, $deprecationWarning
Function expandModuleNames
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function expandModuleNames( $modules ) {
$retval = [];
$exploded = explode( '|', $modules );
foreach ( $exploded as $group ) {
if ( strpos( $group, ',' ) === 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 trimArray
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private static function trimArray( array &$array ): void {
$i = count( $array );
while ( $i-- ) {
if ( $array[$i] === null
|| $array[$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
Function preloadModuleInfo
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function preloadModuleInfo( array $moduleNames, Context $context ) {
// Load all tracked indirect file dependencies for the modules
$vary = Module::getVary( $context );
$entitiesByModule = [];
foreach ( $moduleNames as $moduleName ) {
- 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 addSource
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function addSource( $sources, $loadUrl = null ) {
if ( !is_array( $sources ) ) {
$sources = [ $sources => $loadUrl ];
}
foreach ( $sources as $id => $source ) {
- 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 makeLoaderQuery
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function makeLoaderQuery( array $modules, $lang, $skin, $user = null,
$version = null, $debug = Context::DEBUG_OFF, $only = null,
$printable = false, $handheld = null, array $extraQuery = []
) {
$query = [
- 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 addFileContent
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function addFileContent( MinifierState $minifier,
$moduleName, $sourceType, $sourceIndex, array $file
) {
$isScript = ( $file['type'] ?? 'script' ) === 'script';
/** @var FilePath|null $filePath */
- 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 ( $array[$i] === null
|| $array[$i] === []
|| ( $array[$i] instanceof HtmlJsCode && $array[$i]->value === '{}' )
|| ( $array[$i] instanceof stdClass && self::isEmptyObject( $array[$i] ) )
) {
Method addFileContent
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private function addFileContent( MinifierState $minifier,
$moduleName, $sourceType, $sourceIndex, array $file
Method addOneModuleResponse
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Context $context, MinifierState $minifier, $name, Module $module, &$headers
Function register
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function register( $name, array $info = null ) {
// Allow multiple modules to be registered in one call
$registrations = is_array( $name ) ? $name : [ $name => $info ];
foreach ( $registrations as $name => $info ) {
// Warn on duplicate registrations
- 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 [ $response, $offset ];
Avoid too many return
statements within this method. Open
return [ $minifier->getMinifiedOutput(), null ];
Function getModule
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getModule( $name ) {
if ( !isset( $this->modules[$name] ) ) {
if ( !isset( $this->moduleInfos[$name] ) ) {
// No such module
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 getCombinedVersion
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getCombinedVersion( Context $context, array $moduleNames ) {
if ( !$moduleNames ) {
return '';
}
$hashes = [];
- 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"