File WebRequest.php
has 651 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Deal with importing all those nasty globals and things
*
* Copyright © 2003 Brooke Vibber <bvibber@wikimedia.org>
WebRequest
has 67 functions (exceeds 20 allowed). Consider refactoring. Open
class WebRequest {
/**
* The parameters from $_GET, $_POST and the path router
* @var array
*/
Function getIP
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
public function getIP(): string {
global $wgUsePrivateIPs;
# Return cached result
if ( $this->ip !== 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 getPathInfo
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
protected function getPathInfo( $want = 'all' ) {
// PATH_INFO is mangled due to https://bugs.php.net/bug.php?id=31892
// And also by Apache 2.x, double slashes are converted to single slashes.
// So we will use REQUEST_URI if possible.
$url = $this->getServerInfo( 'REQUEST_URI' );
- 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 getIP
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getIP(): string {
global $wgUsePrivateIPs;
# Return cached result
if ( $this->ip !== null ) {
Method getPathInfo
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function getPathInfo( $want = 'all' ) {
// PATH_INFO is mangled due to https://bugs.php.net/bug.php?id=31892
// And also by Apache 2.x, double slashes are converted to single slashes.
// So we will use REQUEST_URI if possible.
$url = $this->getServerInfo( 'REQUEST_URI' );
Function detectServer
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public static function detectServer( $assumeProxiesUseDefaultProtocolPorts = null ) {
$assumeProxiesUseDefaultProtocolPorts ??= $GLOBALS['wgAssumeProxiesUseDefaultProtocolPorts'];
$proto = self::detectProtocol();
$stdPort = $proto === 'https' ? 443 : 80;
- 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 getAcceptLang
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getAcceptLang() {
// Modified version of code found at
// http://www.thefutureoftheweb.com/blog/use-accept-language-header
$acceptLang = $this->getHeader( 'Accept-Language' );
if ( !$acceptLang ) {
Function matchURLForCDN
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function matchURLForCDN( array $cdnUrls ) {
$services = MediaWikiServices::getInstance();
$reqUrl = (string)$services->getUrlUtils()->expand( $this->getRequestURL(), PROTO_INTERNAL );
$config = $services->getMainConfig();
if ( $config->get( MainConfigNames::CdnMatchParameterOrder ) ) {
- 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 extractTitle
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function extractTitle( $path, $bases, $key = false ) {
foreach ( (array)$bases as $keyValue => $base ) {
// Find the part after $wgArticlePath
$base = str_replace( '$1', '', $base );
if ( str_starts_with( $path, $base ) ) {
- 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 getGlobalRequestURL
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function getGlobalRequestURL() {
// This method is called on fatal errors; it should not depend on anything complex.
if ( isset( $_SERVER['REQUEST_URI'] ) && strlen( $_SERVER['REQUEST_URI'] ) ) {
$base = $_SERVER['REQUEST_URI'];
- 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 detectServer
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function detectServer( $assumeProxiesUseDefaultProtocolPorts = null ) {
$assumeProxiesUseDefaultProtocolPorts ??= $GLOBALS['wgAssumeProxiesUseDefaultProtocolPorts'];
$proto = self::detectProtocol();
$stdPort = $proto === 'https' ? 443 : 80;
Method getGlobalRequestURL
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getGlobalRequestURL() {
// This method is called on fatal errors; it should not depend on anything complex.
if ( isset( $_SERVER['REQUEST_URI'] ) && strlen( $_SERVER['REQUEST_URI'] ) ) {
$base = $_SERVER['REQUEST_URI'];
Method matchURLForCDN
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function matchURLForCDN( array $cdnUrls ) {
$services = MediaWikiServices::getInstance();
$reqUrl = (string)$services->getUrlUtils()->expand( $this->getRequestURL(), PROTO_INTERNAL );
$config = $services->getMainConfig();
if ( $config->get( MainConfigNames::CdnMatchParameterOrder ) ) {
Function getLimitOffsetForUser
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getLimitOffsetForUser( UserIdentity $user, $deflimit = 50, $optionname = 'rclimit' ) {
$limit = $this->getInt( 'limit', 0 );
if ( $limit < 0 ) {
$limit = 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"