Passed
Push — master ( d3a894...a569b2 )
by Christian
04:02
created

FindUser::find()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 32
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 22
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 32
ccs 21
cts 21
cp 1
crap 2
rs 9.568
1
<?php
2
3
namespace Omatech\Mage\Core\Repositories\Users;
4
5
use Omatech\Mage\Core\Domains\Users\Contracts\FindUserInterface;
6
use Omatech\Mage\Core\Repositories\UserBaseRepository;
7
8
class FindUser extends UserBaseRepository implements FindUserInterface
9
{
10
    /**
11
     * @return mixed|null
12
     */
13 4
    public function find(int $id)
14
    {
15 4
        $user = $this->query()->find($id);
16
17 4
        if (null === $user) {
18 1
            return null;
19
        }
20
21
        $permissions = array_map(static function ($permission) {
22 1
            return app('mage.permissions')::find($permission['id']);
0 ignored issues
show
Bug introduced by
The method find() does not exist on Illuminate\Contracts\Foundation\Application. ( Ignorable by Annotation )

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

22
            return app('mage.permissions')::/** @scrutinizer ignore-call */ find($permission['id']);

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...
23 3
        }, $user->permissions->toArray());
24
25
        $roles = array_map(static function ($role) {
26 1
            return app('mage.roles')::find($role['id']);
27 3
        }, $user->roles->toArray());
28
29 3
        $user = app('mage.users')::fromArray([
0 ignored issues
show
Bug introduced by
The method fromArray() does not exist on Illuminate\Contracts\Foundation\Application. ( Ignorable by Annotation )

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

29
        $user = app('mage.users')::/** @scrutinizer ignore-call */ fromArray([

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...
30 3
            'id'                => $user->id,
31 3
            'name'              => $user->name,
32 3
            'language'          => $user->language,
33 3
            'email'             => $user->email,
34 3
            'email_verified_at' => $user->verified_at,
35 3
            'password'          => $user->password,
36 3
            'remember_token'    => $user->remember_token,
37 3
            'created_at'        => $user->created_at,
38 3
            'updated_at'        => $user->updated_at,
39
        ]);
40
41 3
        $user->assignPermissions($permissions);
42 3
        $user->assignRoles($roles);
43
44 3
        return $user;
45
    }
46
}
47