Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 30 | class AuthManagerAuthPlugin extends \AuthPlugin { |
||
|
|
|||
| 31 | /** @var string|null */ |
||
| 32 | protected $domain = null; |
||
| 33 | |||
| 34 | /** @var \\Psr\\Log\\LoggerInterface */ |
||
| 35 | protected $logger = null; |
||
| 36 | |||
| 37 | public function __construct() { |
||
| 40 | |||
| 41 | public function userExists( $name ) { |
||
| 44 | |||
| 45 | public function authenticate( $username, $password ) { |
||
| 46 | $data = [ |
||
| 47 | 'username' => $username, |
||
| 48 | 'password' => $password, |
||
| 49 | ]; |
||
| 50 | View Code Duplication | if ( $this->domain !== null && $this->domain !== '' ) { |
|
| 51 | $data['domain'] = $this->domain; |
||
| 52 | } |
||
| 53 | $reqs = AuthManager::singleton()->getAuthenticationRequests( AuthManager::ACTION_LOGIN ); |
||
| 54 | $reqs = AuthenticationRequest::loadRequestsFromSubmission( $reqs, $data ); |
||
| 55 | |||
| 56 | $res = AuthManager::singleton()->beginAuthentication( $reqs, 'null:' ); |
||
| 57 | switch ( $res->status ) { |
||
| 58 | case AuthenticationResponse::PASS: |
||
| 59 | return true; |
||
| 60 | case AuthenticationResponse::FAIL: |
||
| 61 | // Hope it's not a PreAuthenticationProvider that failed... |
||
| 62 | $msg = $res->message instanceof \Message ? $res->message : new \Message( $res->message ); |
||
| 63 | $this->logger->info( __METHOD__ . ': Authentication failed: ' . $msg->plain() ); |
||
| 64 | return false; |
||
| 65 | default: |
||
| 66 | throw new \BadMethodCallException( |
||
| 67 | 'AuthManager does not support such simplified authentication' |
||
| 68 | ); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | public function modifyUITemplate( &$template, &$type ) { |
||
| 75 | |||
| 76 | public function setDomain( $domain ) { |
||
| 79 | |||
| 80 | public function getDomain() { |
||
| 87 | |||
| 88 | public function validDomain( $domain ) { |
||
| 92 | |||
| 93 | public function updateUser( &$user ) { |
||
| 97 | |||
| 98 | public function autoCreate() { |
||
| 101 | |||
| 102 | public function allowPropChange( $prop = '' ) { |
||
| 105 | |||
| 106 | public function allowPasswordChange() { |
||
| 116 | |||
| 117 | public function allowSetLocalPassword() { |
||
| 121 | |||
| 122 | public function setPassword( $user, $password ) { |
||
| 147 | |||
| 148 | public function updateExternalDB( $user ) { |
||
| 153 | |||
| 154 | public function updateExternalDBGroups( $user, $addgroups, $delgroups = [] ) { |
||
| 158 | |||
| 159 | public function canCreateAccounts() { |
||
| 162 | |||
| 163 | public function addUser( $user, $password, $email = '', $realname = '' ) { |
||
| 172 | |||
| 173 | public function strict() { |
||
| 177 | |||
| 178 | public function strictUserAuth( $username ) { |
||
| 182 | |||
| 183 | public function initUser( &$user, $autocreate = false ) { |
||
| 186 | |||
| 187 | public function getCanonicalName( $username ) { |
||
| 191 | |||
| 192 | public function getUserInstance( User &$user ) { |
||
| 195 | |||
| 196 | public function domainList() { |
||
| 199 | } |
||
| 200 | |||
| 230 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.