Issues (63)

Branch: master

app/Console/CreateAdmin.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Thinktomorrow\Chief\App\Console;
4
5
use Illuminate\Support\Facades\Artisan;
6
use Thinktomorrow\Chief\Admin\Authorization\AuthorizationDefaults;
7
8
class CreateAdmin extends BaseCommand
9
{
10
    protected $signature = 'chief:admin {--dev}';
11
    protected $description = 'Create a new chief admin user';
12
13
    public function handle(): void
14
    {
15
        $this->settingPermissionsAndRoles();
16
17
        $firstname = null;
18
        $lastname = null;
19
20
        while (! $firstname) {
21
            $firstname = $this->ask('Firstname');
22
        }
23
24
        while (! $lastname) {
25
            $lastname = $this->ask('Lastname');
26
        }
27
28
        $email = $this->ask('Email');
29
30
        $password = $this->askPassword();
31
32
        if ($this->option('dev')) {
33
            $role = 'developer';
34
        } else {
35
            $role = 'admin';
36
        }
37
38
        $this->createUser($firstname, $lastname, $email, $password, [$role]);
0 ignored issues
show
It seems like $password can also be of type null; however, parameter $password of Thinktomorrow\Chief\App\...seCommand::createUser() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

38
        $this->createUser($firstname, $lastname, $email, /** @scrutinizer ignore-type */ $password, [$role]);
Loading history...
39
40
        $this->info($firstname . ' ' . $lastname . ' succesfully added as admin user.');
41
    }
42
43
    private function settingPermissionsAndRoles(): void
44
    {
45
        AuthorizationDefaults::permissions()->each(function ($permissionName) {
46
            Artisan::call('chief:permission', ['name' => $permissionName]);
47
        });
48
49
        AuthorizationDefaults::roles()->each(function ($defaultPermissions, $roleName) {
50
            Artisan::call('chief:role', ['name' => $roleName, '--permissions' => implode(',', $defaultPermissions)]);
51
        });
52
53
        $this->info('Default permissions and roles');
54
    }
55
}
56