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

UserHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 27
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolveUser() 0 20 5
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