File User.php
has 1823 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Implements the User class for the %MediaWiki software.
*
* This program is free software; you can redistribute it and/or modify
User
has 146 functions (exceeds 20 allowed). Consider refactoring. Open
#[AllowDynamicProperties]
class User implements Authority, UserIdentity, UserEmailContact {
use DebugInfoTrait;
use ProtectedHookAccessorTrait;
use WikiAwareEntityTrait;
Function loadFromRow
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
protected function loadFromRow( $row, $data = null ) {
if ( !is_object( $row ) ) {
throw new InvalidArgumentException( '$row must be an object' );
}
- 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 loadFromRow
has 80 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function loadFromRow( $row, $data = null ) {
if ( !is_object( $row ) ) {
throw new InvalidArgumentException( '$row must be an object' );
}
Method load
has 72 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function load( $flags = IDBAccessObject::READ_NORMAL ) {
global $wgFullyInitialised;
if ( $this->mLoadedItems === true ) {
return;
Method newSystemUser
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function newSystemUser( $name, $options = [] ) {
$options += [
'validate' => UserRigorOptions::RIGOR_VALID,
'create' => true,
'steal' => false,
Function clearInstanceCache
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public function clearInstanceCache( $reloadFrom = false ) {
global $wgFullyInitialised;
$this->mDatePreference = null;
$this->mHash = 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 load
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public function load( $flags = IDBAccessObject::READ_NORMAL ) {
global $wgFullyInitialised;
if ( $this->mLoadedItems === true ) {
return;
- 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 addToDatabase
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function addToDatabase() {
$this->load();
if ( !$this->mToken ) {
$this->setToken(); // init token
}
Method saveSettings
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function saveSettings() {
if ( MediaWikiServices::getInstance()->getReadOnlyMode()->isReadOnly() ) {
// @TODO: caller should deal with this instead!
// This should really just be an exception.
MWExceptionHandler::logException( new DBExpectedError(
Method insertNewUser
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function insertNewUser( callable $insertActor, $name, $params = [] ) {
foreach ( [ 'password', 'newpassword', 'newpass_time', 'password_expires' ] as $field ) {
if ( isset( $params[$field] ) ) {
wfDeprecated( __METHOD__ . " with param '$field'", '1.27' );
unset( $params[$field] );
Method loadFromCache
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function loadFromCache() {
global $wgFullyInitialised;
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
$data = $cache->getWithSetCallback(
Method sendConfirmationMail
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function sendConfirmationMail( $type = 'created' ) {
global $wgLang;
$expiration = null; // gets passed-by-ref and defined in next line.
$token = $this->confirmationToken( $expiration );
$url = $this->confirmationTokenUrl( $token );
Function newSystemUser
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public static function newSystemUser( $name, $options = [] ) {
$options += [
'validate' => UserRigorOptions::RIGOR_VALID,
'create' => true,
'steal' => 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
Method setEmailWithConfirmation
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setEmailWithConfirmation( string $str ) {
$config = MediaWikiServices::getInstance()->getMainConfig();
$enableEmail = $config->get( MainConfigNames::EnableEmail );
if ( !$enableEmail ) {
Method clearInstanceCache
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function clearInstanceCache( $reloadFrom = false ) {
global $wgFullyInitialised;
$this->mDatePreference = null;
$this->mHash = false;
Method doLogout
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function doLogout() {
$session = $this->getRequest()->getSession();
if ( !$session->canSetUser() ) {
LoggerFactory::getInstance( 'session' )
->warning( __METHOD__ . ": Cannot log out of an immutable session" );
Function setEmailWithConfirmation
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function setEmailWithConfirmation( string $str ) {
$config = MediaWikiServices::getInstance()->getMainConfig();
$enableEmail = $config->get( MainConfigNames::EnableEmail );
if ( !$enableEmail ) {
- 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 getExperienceLevel
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getExperienceLevel() {
$mainConfig = MediaWikiServices::getInstance()->getMainConfig();
$learnerEdits = $mainConfig->get( MainConfigNames::LearnerEdits );
$experiencedUserEdits = $mainConfig->get( MainConfigNames::ExperiencedUserEdits );
$learnerMemberSince = $mainConfig->get( MainConfigNames::LearnerMemberSince );
Method setCookies
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setCookies( $request = null, $secure = null, $rememberMe = false ) {
$this->load();
if ( $this->mId == 0 ) {
return;
}
Function setCookies
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function setCookies( $request = null, $secure = null, $rememberMe = false ) {
$this->load();
if ( $this->mId == 0 ) {
return;
}
- 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 $user;
Function getBlock
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getBlock(
$freshness = IDBAccessObject::READ_NORMAL,
$disableIpBlockExemptChecking = false
): ?Block {
if ( is_bool( $freshness ) ) {
- 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 getToken
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getToken( $forceCreation = true ) {
$authenticationTokenVersion = MediaWikiServices::getInstance()
->getMainConfig()->get( MainConfigNames::AuthenticationTokenVersion );
$this->load();
- 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 getId
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getId( $wikiId = self::LOCAL ): int {
$this->assertWiki( $wikiId );
if ( $this->mId === null && $this->mName !== null ) {
$userNameUtils = MediaWikiServices::getInstance()->getUserNameUtils();
if ( $userNameUtils->isIP( $this->mName ) || ExternalUserNames::isExternal( $this->mName ) ) {
- 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 getExperienceLevel
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getExperienceLevel() {
$mainConfig = MediaWikiServices::getInstance()->getMainConfig();
$learnerEdits = $mainConfig->get( MainConfigNames::LearnerEdits );
$experiencedUserEdits = $mainConfig->get( MainConfigNames::ExperiencedUserEdits );
$learnerMemberSince = $mainConfig->get( MainConfigNames::LearnerMemberSince );
- 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"