AdminUserTransformer   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 0 18 1
A getRolesAttr() 0 11 3
A getPermissionsAttr() 0 11 3
1
<?php
2
3
namespace Yeelight\Transformers;
4
5
use Yeelight\Models\AdminUser;
6
7
/**
8
 * Class AdminUserTransformer
9
 *
10
 * @category Yeelight
11
 *
12
 * @package Yeelight\Transformers
13
 *
14
 * @author Sheldon Lee <[email protected]>
15
 *
16
 * @license https://opensource.org/licenses/MIT MIT
17
 *
18
 * @link https://www.yeelight.com
19
 */
20
class AdminUserTransformer extends BaseTransformer
21
{
22
    /**
23
     * Transform the AdminUser entity.
24
     *
25
     * @param AdminUser $model
26
     *
27
     * @return array
28
     */
29
    public function transform(AdminUser $model)
30
    {
31
        return [
32
            'id'                => (int) $model->id,
33
            'username'          => (string) $model->username,
0 ignored issues
show
Bug Best Practice introduced by
The property username does not exist on Yeelight\Models\AdminUser. Since you implemented __get, consider adding a @property annotation.
Loading history...
34
            'name'              => (string) $model->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Yeelight\Models\AdminUser. Since you implemented __get, consider adding a @property annotation.
Loading history...
35
            'avatar'            => (string) $model->getYeelightImageUrl(),
36
            'yeelight_image_id' => (int) $model->yeelight_image_id,
37
            'password'          => (string) $model->password,
38
            'remember_token'    => (string) $model->remember_token,
0 ignored issues
show
Bug Best Practice introduced by
The property remember_token does not exist on Yeelight\Models\AdminUser. Since you implemented __get, consider adding a @property annotation.
Loading history...
39
            'roles'             => (array) $model->roles,
0 ignored issues
show
Bug Best Practice introduced by
The property roles does not exist on Yeelight\Models\AdminUser. Since you implemented __get, consider adding a @property annotation.
Loading history...
40
            'role_ids'          => (array) $model->roles->pluck($model->getKeyName())->toArray(),
0 ignored issues
show
Bug introduced by
The method pluck() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
            'role_ids'          => (array) $model->roles->/** @scrutinizer ignore-call */ pluck($model->getKeyName())->toArray(),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
            'roles_str'         => (string) $this->getRolesAttr($model),
42
            'permissions'       => (array) $model->permissions,
0 ignored issues
show
Bug Best Practice introduced by
The property permissions does not exist on Yeelight\Models\AdminUser. Since you implemented __get, consider adding a @property annotation.
Loading history...
43
            'permission_ids'    => (array) $model->permissions->pluck($model->getKeyName())->toArray(),
0 ignored issues
show
Bug introduced by
The method pluck() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
            'permission_ids'    => (array) $model->permissions->/** @scrutinizer ignore-call */ pluck($model->getKeyName())->toArray(),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
            'permissions_str'   => (string) $this->getPermissionsAttr($model),
45
            'created_at'        => (string) $model->created_at,
46
            'updated_at'        => (string) $model->updated_at,
47
        ];
48
    }
49
50
    public function getRolesAttr(AdminUser $model)
51
    {
52
        $roles = "<div style='margin-bottom: 5px;'>";
53
        $roles .= collect($model->roles)->map(function ($role, $index) {
0 ignored issues
show
Bug Best Practice introduced by
The property roles does not exist on Yeelight\Models\AdminUser. Since you implemented __get, consider adding a @property annotation.
Loading history...
54
            $br = $index && $index % 3 == 0 ? '</div><div style=\'margin-bottom: 5px;\'>' : '';
55
56
            return "<span class='label label-success'>{$role->name}</span>{$br}";
57
        })->implode('&nbsp;');
58
        $roles .= '</div>';
59
60
        return $roles;
61
    }
62
63
    public function getPermissionsAttr(AdminUser $model)
64
    {
65
        $permissions = "<div style='margin-bottom: 5px;'>";
66
        $permissions .= collect($model->permissions)->map(function ($permission, $index) {
0 ignored issues
show
Bug Best Practice introduced by
The property permissions does not exist on Yeelight\Models\AdminUser. Since you implemented __get, consider adding a @property annotation.
Loading history...
67
            $br = $index && $index % 3 == 0 ? '</div><div style=\'margin-bottom: 5px;\'>' : '';
68
69
            return "<span class='label label-success'>{$permission->name}</span>{$br}";
70
        })->implode('&nbsp;');
71
        $permissions .= '</div>';
72
73
        return $permissions;
74
    }
75
}
76