TenantSeed   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 51
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 16 2
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Models\Tenant;
6
use App\Services\TenantManager;
7
use Illuminate\Console\Command;
8
use Symfony\Component\Console\Exception\RuntimeException;
9
10
class TenantSeed extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'tenant:seed {tenantId}';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Seed teenant with necessary data';
25
26
    protected $tenantManager;
27
28
    /**
29
     * Create a new command instance.
30
     *
31
     * @param TenantManager $tenantManager
32
     */
33
    public function __construct(TenantManager $tenantManager)
34
    {
35
        parent::__construct();
36
37
        $this->tenantManager = $tenantManager;
38
    }
39
40
    /**
41
     * Execute the console command.
42
     *
43
     * @return mixed
44
     */
45
    public function handle()
46
    {
47
        $tenantId = $this->argument('tenantId');
48
        $tenant = Tenant::find($tenantId);
49
50
        if (!$tenant) {
51
            throw new RuntimeException('Tenant with ID = '.$tenantId.' does not exist.');
0 ignored issues
show
Bug introduced by
Are you sure $tenantId of type array|null|string can be used in concatenation? ( Ignorable by Annotation )

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

51
            throw new RuntimeException('Tenant with ID = './** @scrutinizer ignore-type */ $tenantId.' does not exist.');
Loading history...
52
        }
53
54
        $this->tenantManager->setTenant($tenant);
55
        \DB::purge('tenant');
56
57
        $seeder = new \RolesAndPermissionsSeeder('tenant');
58
        $seeder->run(null);
0 ignored issues
show
Unused Code introduced by
The call to RolesAndPermissionsSeeder::run() has too many arguments starting with null. ( Ignorable by Annotation )

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

58
        $seeder->/** @scrutinizer ignore-call */ 
59
                 run(null);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
59
60
        $this->info('Data have been seeded for tenant with subdomain \''.$tenant->subdomain.'\'.');
61
    }
62
}
63