wikimedia/mediawiki-core

View on GitHub
includes/auth/AbstractTemporaryPasswordPrimaryAuthenticationProvider.php

Summary

Maintainability
D
2 days
Test Coverage

File AbstractTemporaryPasswordPrimaryAuthenticationProvider.php has 312 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

    Function providerAllowsAuthenticationDataChange has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        public function providerAllowsAuthenticationDataChange(
            AuthenticationRequest $req, $checkData = true
        ) {
            if ( get_class( $req ) !== TemporaryPasswordAuthenticationRequest::class ) {
                // We don't really ignore it, but this is what the caller expects.

    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 providerAllowsAuthenticationDataChange has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function providerAllowsAuthenticationDataChange(
            AuthenticationRequest $req, $checkData = true
        ) {
            if ( get_class( $req ) !== TemporaryPasswordAuthenticationRequest::class ) {
                // We don't really ignore it, but this is what the caller expects.

      Method beginPrimaryAuthentication has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function beginPrimaryAuthentication( array $reqs ) {
              $req = AuthenticationRequest::getRequestByClass( $reqs, PasswordAuthenticationRequest::class );
              if ( !$req || $req->username === null || $req->password === null ) {
                  return AuthenticationResponse::newAbstain();
              }

        Method sendPasswordResetEmail has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function sendPasswordResetEmail( TemporaryPasswordAuthenticationRequest $req ): void {
                $user = User::newFromName( $req->username );
                if ( !$user ) {
                    return;
                }

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

              public function testForAccountCreation( $user, $creator, array $reqs ) {
                  /** @var TemporaryPasswordAuthenticationRequest $req */
                  $req = AuthenticationRequest::getRequestByClass(
                      $reqs, TemporaryPasswordAuthenticationRequest::class
                  );
          Severity: Minor
          Found in includes/auth/AbstractTemporaryPasswordPrimaryAuthenticationProvider.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 $sv;
          Severity: Major
          Found in includes/auth/AbstractTemporaryPasswordPrimaryAuthenticationProvider.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                                    return \StatusValue::newFatal( 'passwordreset-nosuchcaller', $req->caller );
            Severity: Major
            Found in includes/auth/AbstractTemporaryPasswordPrimaryAuthenticationProvider.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return $this->failResponse( $req );
              Severity: Major
              Found in includes/auth/AbstractTemporaryPasswordPrimaryAuthenticationProvider.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return AuthenticationResponse::newPass( $username );
                Severity: Major
                Found in includes/auth/AbstractTemporaryPasswordPrimaryAuthenticationProvider.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                      return \StatusValue::newFatal( 'passwordreset-emaildisabled' );
                  Severity: Major
                  Found in includes/auth/AbstractTemporaryPasswordPrimaryAuthenticationProvider.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                        return \StatusValue::newFatal( 'throttled-mailpassword',
                                            round( $this->passwordReminderResendTime, 3 ) );
                    Severity: Major
                    Found in includes/auth/AbstractTemporaryPasswordPrimaryAuthenticationProvider.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return [];
                      Severity: Major
                      Found in includes/auth/AbstractTemporaryPasswordPrimaryAuthenticationProvider.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                            return \StatusValue::newFatal( 'passwordreset-nocaller' );
                        Severity: Major
                        Found in includes/auth/AbstractTemporaryPasswordPrimaryAuthenticationProvider.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return [ new TemporaryPasswordAuthenticationRequest ];
                          Severity: Major
                          Found in includes/auth/AbstractTemporaryPasswordPrimaryAuthenticationProvider.php - About 30 mins to fix

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

                                public function beginPrimaryAuthentication( array $reqs ) {
                                    $req = AuthenticationRequest::getRequestByClass( $reqs, PasswordAuthenticationRequest::class );
                                    if ( !$req || $req->username === null || $req->password === null ) {
                                        return AuthenticationResponse::newAbstain();
                                    }
                            Severity: Minor
                            Found in includes/auth/AbstractTemporaryPasswordPrimaryAuthenticationProvider.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 beginPrimaryAccountCreation has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                                public function beginPrimaryAccountCreation( $user, $creator, array $reqs ) {
                                    /** @var TemporaryPasswordAuthenticationRequest $req */
                                    $req = AuthenticationRequest::getRequestByClass(
                                        $reqs, TemporaryPasswordAuthenticationRequest::class
                                    );
                            Severity: Minor
                            Found in includes/auth/AbstractTemporaryPasswordPrimaryAuthenticationProvider.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