MyInfoForm::handleInternal()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 13
ccs 0
cts 13
cp 0
rs 9.9
cc 1
nc 1
nop 0
crap 2
1
<?php
2
namespace App\Http\Api\Backend\Form;
3
4
use Yii;
5
6
class MyInfoForm extends UserForm
7
{
8
    protected function handleInternal()
9
    {
10
        $user = $this->getUser();
11
        return [
12
            'id' => $user->id,
13
            'username' => $user->username,
14
            'name' => $user->name,
15
            'first_name' => $user->first_name,
16
            'last_name' => $user->last_name,
17
            'email' => $user->email,
18
            'avatar' => $user->avatar,
19
            'language' => $user->language,
0 ignored issues
show
Bug Best Practice introduced by
The property language does not exist on App\Model\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
20
            'permissions' => $this->getPermissions(),
21
        ];
22
    }
23
24
    protected function getPermissions()
25
    {
26
        $user = $this->getUser();
27
        $auth = Yii::$app->getAuthManager();
28
        $permissions = $auth->getPermissionsByUser($user->id);
29
        $names = array_column($permissions, 'name');
30
        return $names;
31
    }
32
}
33