Issues (197)

src/Commands/SeedMakeCommand.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Salah3id\Domains\Commands;
4
5
use Illuminate\Support\Str;
6
use Salah3id\Domains\Support\Config\GenerateConfigReader;
7
use Salah3id\Domains\Support\Stub;
8
use Salah3id\Domains\Traits\CanClearDomainsCache;
9
use Salah3id\Domains\Traits\DomainCommandTrait;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputOption;
12
13
class SeedMakeCommand extends GeneratorCommand
14
{
15
    use DomainCommandTrait;
16
    use CanClearDomainsCache;
17
18
    protected $argumentName = 'name';
19
20
    /**
21
     * The console command name.
22
     *
23
     * @var string
24
     */
25
    protected $name = 'domain:make-seed';
26
27
    /**
28
     * The console command description.
29
     *
30
     * @var string
31
     */
32
    protected $description = 'Generate new seeder for the specified domain.';
33
34
    /**
35
     * Get the console command arguments.
36
     *
37
     * @return array
38
     */
39
    protected function getArguments()
40
    {
41
        return [
42
            ['name', InputArgument::REQUIRED, 'The name of seeder will be created.'],
43
            ['domain', InputArgument::OPTIONAL, 'The name of domain will be used.'],
44
        ];
45
    }
46
47
    /**
48
     * Get the console command options.
49
     *
50
     * @return array
51
     */
52
    protected function getOptions()
53
    {
54
        return [
55
            [
56
                'master',
57
                null,
58
                InputOption::VALUE_NONE,
59
                'Indicates the seeder will created is a master database seeder.',
60
            ],
61
        ];
62
    }
63
64
    /**
65
     * @return mixed
66
     */
67
    protected function getTemplateContents()
68
    {
69
        $domain = $this->laravel['domains']->findOrFail($this->getDomainName());
70
71
        return (new Stub('/seeder.stub', [
72
            'NAME' => $this->getSeederName(),
73
            'DOMAIN' => $this->getDomainName(),
74
            'NAMESPACE' => $this->getClassNamespace($domain),
75
76
        ]))->render();
77
    }
78
79
    /**
80
     * @return mixed
81
     */
82
    protected function getDestinationFilePath()
83
    {
84
        $this->clearCache();
85
86
        $path = $this->laravel['domains']->getDomainPath($this->getDomainName());
87
88
        $seederPath = GenerateConfigReader::read('seeder');
89
90
        return $path . $seederPath->getPath() . '/' . $this->getSeederName() . '.php';
91
    }
92
93
    /**
94
     * Get seeder name.
95
     *
96
     * @return string
97
     */
98
    private function getSeederName()
99
    {
100
        $end = $this->option('master') ? 'DatabaseSeeder' : 'TableSeeder';
101
102
        return Str::studly($this->argument('name')) . $end;
0 ignored issues
show
It seems like $this->argument('name') can also be of type array; however, parameter $value of Illuminate\Support\Str::studly() 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

102
        return Str::studly(/** @scrutinizer ignore-type */ $this->argument('name')) . $end;
Loading history...
103
    }
104
105
    /**
106
     * Get default namespace.
107
     *
108
     * @return string
109
     */
110
    public function getDefaultNamespace(): string
111
    {
112
        $domain = $this->laravel['domains'];
113
114
        return $domain->config('paths.generator.seeder.namespace') ?: $domain->config('paths.generator.seeder.path', 'Database/Seeders');
115
    }
116
}
117