AbstractPrimaryAuthenticationProvider   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 87
Duplicated Lines 11.49 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 10
loc 87
rs 10
c 0
b 0
f 0
wmc 18
lcom 0
cbo 4

15 Methods

Rating   Name   Duplication   Size   Complexity  
A continuePrimaryAuthentication() 0 3 1
A postAuthentication() 0 2 1
A testUserCanAuthenticate() 0 4 1
A providerNormalizeUsername() 0 4 2
A providerRevokeAccessForUser() 10 10 2
A providerAllowsPropertyChange() 0 3 1
A testForAccountCreation() 0 3 1
A continuePrimaryAccountCreation() 0 3 1
A finishAccountCreation() 0 3 1
A postAccountCreation() 0 2 1
A autoCreatedAccount() 0 2 1
A beginPrimaryAccountLink() 0 9 2
A continuePrimaryAccountLink() 0 3 1
A postAccountLink() 0 2 1
A testUserForCreation() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

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
2
/**
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation; either version 2 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License along
14
 * with this program; if not, write to the Free Software Foundation, Inc.,
15
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
 * http://www.gnu.org/copyleft/gpl.html
17
 *
18
 * @file
19
 * @ingroup Auth
20
 */
21
22
namespace MediaWiki\Auth;
23
24
use User;
25
26
/**
27
 * A base class that implements some of the boilerplate for a PrimaryAuthenticationProvider
28
 *
29
 * @ingroup Auth
30
 * @since 1.27
31
 */
32
abstract class AbstractPrimaryAuthenticationProvider extends AbstractAuthenticationProvider
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces between "AbstractAuthenticationProvider" and comma; 1 found
Loading history...
33
	implements PrimaryAuthenticationProvider
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
34
{
35
36
	public function continuePrimaryAuthentication( array $reqs ) {
37
		throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' );
38
	}
39
40
	public function postAuthentication( $user, AuthenticationResponse $response ) {
41
	}
42
43
	public function testUserCanAuthenticate( $username ) {
44
		// Assume it can authenticate if it exists
45
		return $this->testUserExists( $username );
46
	}
47
48
	/**
49
	 * @inheritdoc
50
	 * @note Reimplement this if you do anything other than
51
	 *  User::getCanonicalName( $req->username ) to determine the user being
52
	 *  authenticated.
53
	 */
54
	public function providerNormalizeUsername( $username ) {
55
		$name = User::getCanonicalName( $username );
56
		return $name === false ? null : $name;
57
	}
58
59
	/**
60
	 * @inheritdoc
61
	 * @note Reimplement this if self::getAuthenticationRequests( AuthManager::ACTION_REMOVE )
62
	 *  doesn't return requests that will revoke all access for the user.
63
	 */
64 View Code Duplication
	public function providerRevokeAccessForUser( $username ) {
65
		$reqs = $this->getAuthenticationRequests(
66
			AuthManager::ACTION_REMOVE, [ 'username' => $username ]
67
		);
68
		foreach ( $reqs as $req ) {
69
			$req->username = $username;
70
			$req->action = AuthManager::ACTION_REMOVE;
71
			$this->providerChangeAuthenticationData( $req );
72
		}
73
	}
74
75
	public function providerAllowsPropertyChange( $property ) {
76
		return true;
77
	}
78
79
	public function testForAccountCreation( $user, $creator, array $reqs ) {
80
		return \StatusValue::newGood();
81
	}
82
83
	public function continuePrimaryAccountCreation( $user, $creator, array $reqs ) {
84
		throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' );
85
	}
86
87
	public function finishAccountCreation( $user, $creator, AuthenticationResponse $response ) {
88
		return null;
89
	}
90
91
	public function postAccountCreation( $user, $creator, AuthenticationResponse $response ) {
92
	}
93
94
	public function testUserForCreation( $user, $autocreate, array $options = [] ) {
95
		return \StatusValue::newGood();
96
	}
97
98
	public function autoCreatedAccount( $user, $source ) {
99
	}
100
101
	public function beginPrimaryAccountLink( $user, array $reqs ) {
102
		if ( $this->accountCreationType() === self::TYPE_LINK ) {
103
			throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' );
104
		} else {
105
			throw new \BadMethodCallException(
106
				__METHOD__ . ' should not be called on a non-link provider.'
107
			);
108
		}
109
	}
110
111
	public function continuePrimaryAccountLink( $user, array $reqs ) {
112
		throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' );
113
	}
114
115
	public function postAccountLink( $user, AuthenticationResponse $response ) {
116
	}
117
118
}
119