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

Oauth2UserPatTrait::generatePersonalAccessToken()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 16
rs 9.9332
cc 3
nc 4
nop 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