wikimedia/mediawiki-core

View on GitHub
includes/user/BotPassword.php

Summary

Maintainability
D
1 day
Test Coverage

BotPassword has 23 functions (exceeds 20 allowed). Consider refactoring.
Open

class BotPassword {

    public const APPID_MAXLENGTH = 32;

    /**
Severity: Minor
Found in includes/user/BotPassword.php - About 2 hrs to fix

    Method login has 61 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function login( $username, $password, WebRequest $request ) {
            $enableBotPasswords = MediaWikiServices::getInstance()->getMainConfig()
                ->get( MainConfigNames::EnableBotPasswords );
            $passwordAttemptThrottle = MediaWikiServices::getInstance()->getMainConfig()
                ->get( MainConfigNames::PasswordAttemptThrottle );
    Severity: Major
    Found in includes/user/BotPassword.php - About 2 hrs to fix

      File BotPassword.php has 263 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      /**
       * Utility class for bot passwords
       *
       * This program is free software; you can redistribute it and/or modify
      Severity: Minor
      Found in includes/user/BotPassword.php - About 2 hrs to fix

        Function login has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function login( $username, $password, WebRequest $request ) {
                $enableBotPasswords = MediaWikiServices::getInstance()->getMainConfig()
                    ->get( MainConfigNames::EnableBotPasswords );
                $passwordAttemptThrottle = MediaWikiServices::getInstance()->getMainConfig()
                    ->get( MainConfigNames::PasswordAttemptThrottle );
        Severity: Minor
        Found in includes/user/BotPassword.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

        Function canonicalizeLoginData has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function canonicalizeLoginData( $username, $password ) {
                $sep = self::getSeparator();
                // the strlen check helps minimize the password information obtainable from timing
                if ( strlen( $password ) >= self::PASSWORD_MINLENGTH && str_contains( $username, $sep ) ) {
                    // the separator is not valid in new usernames but might appear in legacy ones
        Severity: Minor
        Found in includes/user/BotPassword.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 self::loginHook( $user, $bp, $performer, Status::newFatal( 'wrongpassword' ) );
        Severity: Major
        Found in includes/user/BotPassword.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                          return self::loginHook( $user, null, $performer, Status::newFatal( $msg ) );
          Severity: Major
          Found in includes/user/BotPassword.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return self::loginHook( $user, $bp, $performer,
                            Status::newFatal( 'botpasswords-restriction-failed' ) );
            Severity: Major
            Found in includes/user/BotPassword.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return self::loginHook( $user, $bp, $performer,
                              Status::newFatal( 'botpasswords-needs-reset', $name, $appId ) );
              Severity: Major
              Found in includes/user/BotPassword.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return Status::newFatal( 'botpasswords-locked' );
                Severity: Major
                Found in includes/user/BotPassword.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return self::loginHook( $user, $bp, $performer,
                              // @phan-suppress-next-line PhanUndeclaredMethod
                              Status::newGood( $provider->newSessionForRequest( $user, $bp, $request ) ) );
                  Severity: Major
                  Found in includes/user/BotPassword.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return self::loginHook( $user, $bp, $performer,
                                    Status::newFatal( 'botpasswords-not-exist', $name, $appId ) );
                    Severity: Major
                    Found in includes/user/BotPassword.php - About 30 mins to fix

                      Function loginHook has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          private static function loginHook( $user, $bp, User $performer, Status $status ) {
                              $extraData = [
                                  'performer' => $performer
                              ];
                              if ( $user instanceof User ) {
                      Severity: Minor
                      Found in includes/user/BotPassword.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