SeedDemoData::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
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 SeedDemoData extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'tenant:seeddemodata {tenantId}';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Seed teenant database with example recruitments and fake candidates';
25
26
    protected $tenantManager;
27
28
    /**
29
     * Create a new command instance.
30
     *
31
     * @return void
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 \ExampleRecruitments();
0 ignored issues
show
Bug introduced by
The call to ExampleRecruitments::__construct() has too few arguments starting with connection. ( Ignorable by Annotation )

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

57
        $seeder = /** @scrutinizer ignore-call */ new \ExampleRecruitments();

This check compares calls to functions or methods with their respective definitions. If the call has less 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...
58
        $seeder->setConnection('tenant');
59
        $seeder->run();
60
61
        $seeder = new \ExampleCandidates();
0 ignored issues
show
Bug introduced by
The call to ExampleCandidates::__construct() has too few arguments starting with connection. ( Ignorable by Annotation )

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

61
        $seeder = /** @scrutinizer ignore-call */ new \ExampleCandidates();

This check compares calls to functions or methods with their respective definitions. If the call has less 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...
62
        $seeder->setConnection('tenant');
63
        $seeder->run();
64
65
        $seeder = new \ExampleStages();
0 ignored issues
show
Bug introduced by
The call to ExampleStages::__construct() has too few arguments starting with connection. ( Ignorable by Annotation )

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

65
        $seeder = /** @scrutinizer ignore-call */ new \ExampleStages();

This check compares calls to functions or methods with their respective definitions. If the call has less 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...
66
        $seeder->setConnection('tenant');
67
        $seeder->run();
68
69
        $seeder = new \ExamplePredefinedMessages();
0 ignored issues
show
Bug introduced by
The call to ExamplePredefinedMessages::__construct() has too few arguments starting with connection. ( Ignorable by Annotation )

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

69
        $seeder = /** @scrutinizer ignore-call */ new \ExamplePredefinedMessages();

This check compares calls to functions or methods with their respective definitions. If the call has less 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...
70
        $seeder->setConnection('tenant');
71
        $seeder->run();
72
73
        $this->info('Demo data have been seeded for tenant with subdomain \''.$tenant->subdomain.'\'.');
74
    }
75
}
76