Completed
Push — develop ( 112c74...31322a )
by Nate
10:28
created

UserHelper::resolveUser()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 0
cts 16
cp 0
rs 9.2888
c 0
b 0
f 0
cc 5
nc 5
nop 1
crap 30
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/jwt/license
6
 * @link       https://www.flipboxfactory.com/jwt/organization/
7
 */
8
9
namespace flipbox\craft\jwt\helpers;
10
11
use Craft;
12
use craft\helpers\User;
13
use yii\web\IdentityInterface;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class UserHelper extends User
20
{
21
    /**
22
     * @param $user
23
     * @return IdentityInterface|null
24
     */
25
    public static function resolveUser($user)
26
    {
27
        if ($user instanceof IdentityInterface) {
28
            return $user;
29
        }
30
31
        if ($user === 'CURRENT_USER') {
32
            return Craft::$app->getUser()->getIdentity();
33
        }
34
35
        if (is_numeric($user)) {
36
            return Craft::$app->getUsers()->getUserById($user);
37
        }
38
39
        if (is_string($user)) {
40
            return Craft::$app->getUsers()->getUserByUsernameOrEmail($user);
41
        }
42
43
        return null;
44
    }
45
}
46