Passed
Pull Request — master (#7)
by
unknown
26:20 queued 11:18
created

Oauth2UserPatTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A generatePersonalAccessToken() 0 16 3
1
<?php
2
3
namespace rhertogh\Yii2Oauth2Server\traits\models;
4
5
use rhertogh\Yii2Oauth2Server\interfaces\models\external\user\Oauth2UserInterface;
6
use rhertogh\Yii2Oauth2Server\Oauth2Module;
7
use Yii;
8
use yii\web\IdentityInterface;
9
10
trait Oauth2UserPatTrait
11
{
12
    public function generatePersonalAccessToken($clientIdentifier, $scope = null, $clientSecret = true)
13
    {
14
        if (property_exists(static::class, 'oauth2ModuleName')) {
15
            $oauth2ModuleName = static::$oauth2ModuleName;
16
        }
17
18
        /** @var Oauth2Module $module */
19
        $module = empty($oauth2ModuleName)
20
            ? Oauth2Module::getInstance()
21
            : Yii::$app->getModule($oauth2ModuleName);
22
23
        return $module->generatePersonalAccessToken(
24
            $clientIdentifier,
25
            $this->id,
26
            $scope,
27
            $clientSecret
28
        );
29
    }
30
}
31