Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
UserIdentityUtils | |
100.00% |
7 / 7 |
|
100.00% |
4 / 4 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isTemp | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isNamed | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
getShortUserTypeInternal | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | namespace MediaWiki\User; |
4 | |
5 | use MediaWiki\User\TempUser\TempUserConfig; |
6 | |
7 | /** |
8 | * Convenience functions for interpreting UserIdentity objects using additional |
9 | * services or config. |
10 | * |
11 | * @since 1.41 |
12 | */ |
13 | class UserIdentityUtils { |
14 | private TempUserConfig $tempUserConfig; |
15 | |
16 | /** |
17 | * @internal |
18 | * |
19 | * @param TempUserConfig $tempUserConfig |
20 | */ |
21 | public function __construct( TempUserConfig $tempUserConfig ) { |
22 | $this->tempUserConfig = $tempUserConfig; |
23 | } |
24 | |
25 | /** |
26 | * Is the user a temporary user? |
27 | * |
28 | * @param UserIdentity $user |
29 | * @return bool |
30 | */ |
31 | public function isTemp( UserIdentity $user ) { |
32 | return $this->tempUserConfig->isTempName( $user->getName() ); |
33 | } |
34 | |
35 | /** |
36 | * Is the user a normal non-temporary registered user? |
37 | * |
38 | * @param UserIdentity $user |
39 | * @return bool |
40 | */ |
41 | public function isNamed( UserIdentity $user ) { |
42 | return $user->isRegistered() |
43 | && !$this->tempUserConfig->isTempName( $user->getName() ); |
44 | } |
45 | |
46 | /** |
47 | * Get user identity type, used for internal logic like tracking statistics per account type. |
48 | * Only for internal use like tracking statistics and meet DRY |
49 | * |
50 | * @internal |
51 | * @param UserIdentity $user |
52 | * @return string |
53 | */ |
54 | public function getShortUserTypeInternal( UserIdentity $user ): string { |
55 | if ( !$user->isRegistered() ) { |
56 | return 'anon'; |
57 | } |
58 | return $this->isTemp( $user ) ? 'temp' : 'named'; |
59 | } |
60 | } |