Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.00% |
4 / 5 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| UserEntity | |
80.00% |
4 / 5 |
|
75.00% |
3 / 4 |
5.20 | |
0.00% |
0 / 1 |
| newFromMWUser | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getIdentifier | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMWUser | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\OAuth\Entity; |
| 4 | |
| 5 | use League\OAuth2\Server\Entities\UserEntityInterface; |
| 6 | use MediaWiki\Extension\OAuth\Backend\Utils; |
| 7 | use MediaWiki\User\User; |
| 8 | |
| 9 | class UserEntity implements UserEntityInterface { |
| 10 | private int $identifier; |
| 11 | |
| 12 | /** |
| 13 | * @param User $user |
| 14 | * @return UserEntity|null |
| 15 | */ |
| 16 | public static function newFromMWUser( User $user ) { |
| 17 | $userId = Utils::getCentralIdFromLocalUser( $user ); |
| 18 | return $userId ? new static( $userId ) : null; |
| 19 | } |
| 20 | |
| 21 | public function __construct( int $identifier ) { |
| 22 | $this->identifier = $identifier; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Return the user's identifier. |
| 27 | */ |
| 28 | public function getIdentifier(): string { |
| 29 | return (string)$this->identifier; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @return User|false |
| 34 | */ |
| 35 | public function getMWUser() { |
| 36 | return Utils::getLocalUserFromCentralId( $this->identifier ); |
| 37 | } |
| 38 | } |