wikimedia/mediawiki-core

View on GitHub
includes/user/User.php

Summary

Maintainability
F
1 wk
Test Coverage

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
Severity: Major
Found in includes/user/User.php - About 4 days to fix

    User has 146 functions (exceeds 20 allowed). Consider refactoring.
    Open

    #[AllowDynamicProperties]
    class User implements Authority, UserIdentity, UserEmailContact {
        use DebugInfoTrait;
        use ProtectedHookAccessorTrait;
        use WikiAwareEntityTrait;
    Severity: Major
    Found in includes/user/User.php - About 2 days to fix

      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' );
              }
      
      
      Severity: Minor
      Found in includes/user/User.php - About 4 hrs to fix

      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' );
              }
      
      
      Severity: Major
      Found in includes/user/User.php - About 3 hrs to fix

        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;
        Severity: Major
        Found in includes/user/User.php - About 2 hrs to fix

          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,
          Severity: Major
          Found in includes/user/User.php - About 2 hrs to fix

            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;
            Severity: Minor
            Found in includes/user/User.php - About 2 hrs to fix

            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;
            Severity: Minor
            Found in includes/user/User.php - About 2 hrs to fix

            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
                    }
            Severity: Major
            Found in includes/user/User.php - About 2 hrs to fix

              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(
              Severity: Major
              Found in includes/user/User.php - About 2 hrs to fix

                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] );
                Severity: Major
                Found in includes/user/User.php - About 2 hrs to fix

                  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(
                  Severity: Minor
                  Found in includes/user/User.php - About 1 hr to fix

                    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 );
                    Severity: Minor
                    Found in includes/user/User.php - About 1 hr to fix

                      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,
                      Severity: Minor
                      Found in includes/user/User.php - About 1 hr to fix

                      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 ) {
                      Severity: Minor
                      Found in includes/user/User.php - About 1 hr to fix

                        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;
                        Severity: Minor
                        Found in includes/user/User.php - About 1 hr to fix

                          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" );
                          Severity: Minor
                          Found in includes/user/User.php - About 1 hr to fix

                            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 ) {
                            Severity: Minor
                            Found in includes/user/User.php - About 1 hr to fix

                            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 );
                            Severity: Minor
                            Found in includes/user/User.php - About 1 hr to fix

                              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;
                                      }
                              Severity: Minor
                              Found in includes/user/User.php - About 1 hr to fix

                                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;
                                        }
                                Severity: Minor
                                Found in includes/user/User.php - About 35 mins to fix

                                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;
                                Severity: Major
                                Found in includes/user/User.php - About 30 mins to fix

                                  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 ) ) {
                                  Severity: Minor
                                  Found in includes/user/User.php - About 25 mins to fix

                                  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();
                                  Severity: Minor
                                  Found in includes/user/User.php - About 25 mins to fix

                                  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 ) ) {
                                  Severity: Minor
                                  Found in includes/user/User.php - About 25 mins to fix

                                  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 );
                                  Severity: Minor
                                  Found in includes/user/User.php - About 25 mins to fix

                                  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

                                  There are no issues that match your filters.

                                  Category
                                  Status