MakeSuperAdmin::checkAuthorization()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Pratiksh\Adminetic\Services;
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
use Pratiksh\Adminetic\Models\Admin\Role;
7
use Pratiksh\Adminetic\Services\Helper\CommandHelper;
8
9
class MakeSuperAdmin extends CommandHelper
10
{
11
    public static function checkAuthorization($authorization_password)
12
    {
13
        return trim($authorization_password) == 'makemesuper';
14
    }
15
16
    public static function make($name, $email, $password)
17
    {
18
        $user = User::firstOrCreate([
19
            'email' => trim($email),
20
        ], [
21
            'name' => trim($name),
22
            'password' => bcrypt($password),
23
        ]);
24
25
        $role = Role::where('name', 'superadmin')->exists()
26
            ? Role::where('name', 'superadmin')->first()
27
            : $role = Role::create([
0 ignored issues
show
Unused Code introduced by
The assignment to $role is dead and can be removed.
Loading history...
28
                'name' => 'superadmin',
29
                'description' => 'This is super admin. This role has authority over everything in this application.',
30
                'level' => 6,
31
            ]);
32
        $user->roles()->attach($role);
33
        $user->profile()->create();
34
    }
35
}
36