Passed
Push — master ( effb91...3e9a54 )
by Reza
04:04
created

UserProvider::getUserModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace EasyPanel\Support\User;
4
5
use App\Models\User;
0 ignored issues
show
Bug introduced by
The type App\Models\User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
class UserProvider
8
{
9
10
    public function makeAdmin($id, $is_super = false)
11
    {
12
        $user = $this->findUser($id);
13
14
        if ($user->panelAdmin()->exists()){
15
            return [
16
                'type' => 'error',
17
                'message' => 'User already is an admin!'
18
            ];
19
        }
20
21
        $user->panelAdmin()->create([
22
            'is_superuser' => $is_super,
23
        ]);
24
25
        return [
26
            'type' => 'success',
27
            'message' => "User '$id' was converted to an admin",
28
        ];
29
    }
30
31
    public function getAdmins()
32
    {
33
        return $this->getUserModel()::query()->whereHas('panelAdmin')->with('panelAdmin')->get();
34
    }
35
36
    public function findUser($id)
37
    {
38
        return $this->getUserModel()::query()->findOrFail($id);
39
    }
40
41
    public function deleteAdmin($id)
42
    {
43
        $user = $this->findUser($id);
44
45
        $user->panelAdmin()->delete();
46
    }
47
48
    private function getUserModel()
49
    {
50
        return config('easy_panel.user_model') ?? User::class;
51
    }
52
53
}
54