AdmineticDummyCommand::__construct()   A
last analyzed

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
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Pratiksh\Adminetic\Console\Commands;
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 Illuminate\Console\Command;
7
use Illuminate\Support\Facades\Artisan;
8
use Illuminate\Support\Facades\DB;
9
use Illuminate\Support\Facades\Hash;
10
use Pratiksh\Adminetic\Models\Admin\Role;
11
12
class AdmineticDummyCommand extends Command
13
{
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'adminetic:dummy';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Fetch dummy data';
27
28
    /**
29
     * Create a new command instance.
30
     *
31
     * @return void
32
     */
33
    public function __construct()
34
    {
35
        parent::__construct();
36
    }
37
38
    /**
39
     * Execute the console command.
40
     *
41
     * @return int
42
     */
43
    public function handle()
44
    {
45
        if (! config('adminetic.migrate_with_dummy', false)) {
46
            // Generating Roles
47
            $roles = [
48
                [
49
                    'name' => 'superadmin',
50
                    'description' => 'This is a super admin user',
51
                    'level' => 5,
52
                ],
53
                [
54
                    'name' => 'admin',
55
                    'description' => 'This is an admin user',
56
                    'level' => 4,
57
                ],
58
                [
59
                    'name' => 'moderator',
60
                    'description' => 'This is an moderator',
61
                    'level' => 3,
62
                ],
63
                [
64
                    'name' => 'editor',
65
                    'description' => 'This is an editor',
66
                    'level' => 2,
67
                ],
68
                [
69
                    'name' => 'user',
70
                    'description' => 'This is an normal user',
71
                    'level' => 1,
72
                ],
73
                [
74
                    'name' => 'unverified',
75
                    'description' => 'This is an unverified user',
76
                    'level' => 0,
77
                ],
78
            ];
79
80
            DB::table('roles')->insert($roles);
81
82
            // Generating Permission
83
            Artisan::call('make:permission Role 2 --onlyFlags');
84
            Artisan::call('make:permission Permission 2 --onlyFlags');
85
            Artisan::call('make:permission User 2 --onlyFlags');
86
87
            Artisan::call('make:permission Setting 2 --onlyFlags');
88
            Artisan::call('make:permission Preference 2 --onlyFlags');
89
90
            // Generating User
91
            $admin = User::create([
92
                'name' => 'Admin User',
93
                'email' => '[email protected]',
94
                'password' => Hash::make('admin123'),
95
            ]);
96
97
            $role = Role::where('name', 'admin')->first();
98
99
            $admin->roles()->attach($role);
100
            $admin->profile()->create();
101
            $this->info('Dummy data seeded ... ✅');
102
        } else {
103
            $this->error('Dummy data seeding failed because seed on migration is turned on config file.');
104
            $this->warning("Change to 'migrate_with_dummy' => false");
0 ignored issues
show
Bug introduced by
The method warning() does not exist on Pratiksh\Adminetic\Conso...s\AdmineticDummyCommand. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

104
            $this->/** @scrutinizer ignore-call */ 
105
                   warning("Change to 'migrate_with_dummy' => false");
Loading history...
105
        }
106
    }
107
}
108