Issues (413)

app/Transformers/AdminRoleTransformer.php (5 issues)

1
<?php
2
3
namespace Yeelight\Transformers;
4
5
use Yeelight\Models\AdminRole;
6
7
/**
8
 * Class AdminRoleTransformer
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 AdminRoleTransformer extends BaseTransformer
21
{
22
    /**
23
     * Transform the AdminRole entity.
24
     *
25
     * @param AdminRole $model
26
     *
27
     * @return array
28
     */
29
    public function transform(AdminRole $model)
30
    {
31
        return [
32
            'id'                => (int) $model->id,
33
            'name'              => (string) $model->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Yeelight\Models\AdminRole. Since you implemented __get, consider adding a @property annotation.
Loading history...
34
            'slug'              => (string) $model->slug,
0 ignored issues
show
Bug Best Practice introduced by
The property slug does not exist on Yeelight\Models\AdminRole. Since you implemented __get, consider adding a @property annotation.
Loading history...
35
            'permissions'       => (array) $model->permissions,
0 ignored issues
show
Bug Best Practice introduced by
The property permissions does not exist on Yeelight\Models\AdminRole. Since you implemented __get, consider adding a @property annotation.
Loading history...
36
            'permission_ids'    => (array) $model->permissions->pluck($model->getKeyName())->toArray(),
0 ignored issues
show
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

36
            '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...
37
            'permissions_str'   => (string) $this->getPermissionsAttr($model),
38
            'created_at'        => (string) $model->created_at,
39
            'updated_at'        => (string) $model->updated_at,
40
        ];
41
    }
42
43
    public function getPermissionsAttr(AdminRole $model)
44
    {
45
        $permissions = "<div style='margin-bottom: 5px;'>";
46
        $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\AdminRole. Since you implemented __get, consider adding a @property annotation.
Loading history...
47
            $br = $index && $index % 3 == 0 ? '</div><div style=\'margin-bottom: 5px;\'>' : '';
48
49
            return "<span class='label label-success'>{$permission->name}</span>{$br}";
50
        })->implode('&nbsp;');
51
        $permissions .= '</div>';
52
53
        return $permissions;
54
    }
55
}
56