Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
55.56% covered (warning)
55.56%
5 / 9
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
UserEntity
55.56% covered (warning)
55.56%
5 / 9
50.00% covered (danger)
50.00%
2 / 4
9.16
0.00% covered (danger)
0.00%
0 / 1
 newFromMWUser
50.00% covered (danger)
50.00%
3 / 6
0.00% covered (danger)
0.00%
0 / 1
4.12
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getIdentifier
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMWUser
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\OAuth\Entity;
4
5use League\OAuth2\Server\Entities\UserEntityInterface;
6use MediaWiki\Extension\OAuth\Backend\Utils;
7use MediaWiki\User\User;
8use MWException;
9
10class UserEntity implements UserEntityInterface {
11
12    /**
13     * @var int
14     */
15    private $identifier;
16
17    /**
18     * @param User $user
19     * @return UserEntity|null
20     */
21    public static function newFromMWUser( User $user ) {
22        try {
23            $userId = Utils::getCentralIdFromLocalUser( $user );
24            if ( !$userId ) {
25                return null;
26            }
27            return new static( $userId );
28        } catch ( MWException $ex ) {
29            return null;
30        }
31    }
32
33    /**
34     * @param int $identifier
35     */
36    public function __construct( $identifier ) {
37        $this->identifier = $identifier;
38    }
39
40    /**
41     * Return the user's identifier.
42     *
43     * @return int
44     */
45    public function getIdentifier() {
46        return $this->identifier;
47    }
48
49    /**
50     * @return User|false
51     */
52    public function getMWUser() {
53        return Utils::getLocalUserFromCentralId( $this->identifier );
54    }
55}