SeedMakeCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 19
c 1
b 0
f 0
dl 0
loc 52
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSeederName() 0 5 2
A getDestinationFilePath() 0 9 1
A getDefaultNamespace() 0 6 2
A getTemplateContents() 0 10 1
1
<?php
2
3
namespace Rawilk\LaravelModules\Commands\Generators;
4
5
use Illuminate\Support\Str;
6
use Rawilk\LaravelModules\Support\Config\GenerateConfigReader;
7
use Rawilk\LaravelModules\Support\Stub;
8
use Rawilk\LaravelModules\Traits\CanClearModulesCache;
9
use Rawilk\LaravelModules\Traits\ModuleCommands;
10
11
class SeedMakeCommand extends GeneratorCommand
12
{
13
    use ModuleCommands, CanClearModulesCache;
14
15
    /** @var string */
16
    protected $argumentName = 'name';
17
18
    /** @var string */
19
    protected $signature = 'module:make-seed
20
                            {name : The name of the seeder class}
21
                            {module? : The name of the module to create the seeder for}
22
                            {--m|master : Indicates the seeder will be the master database seeder}';
23
24
    /** @var string */
25
    protected $description = 'Generate a new seeder for the specified module.';
26
27
    protected function getDefaultNamespace(): string
28
    {
29
        /** @var \Rawilk\LaravelModules\Contracts\Repository $module */
30
        $module = $this->laravel['modules'];
31
32
        return $module->config('paths.generator.seeder.namespace') ?: $module->config('paths.generator.seeder.path', 'database/seeds');
33
    }
34
35
    protected function getDestinationFilePath(): string
36
    {
37
        $this->clearCache();
38
39
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
40
41
        $seederPath = GenerateConfigReader::read('seeder');
42
43
        return $path . $seederPath->getPath() . '/' . $this->getSeederName() . '.php';
44
    }
45
46
    protected function getTemplateContents(): string
47
    {
48
        /** @var \Rawilk\LaravelModules\Module $module */
49
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
50
51
        return (new Stub('/seeder.stub', [
52
            'NAME'      => $this->getSeederName(),
53
            'MODULE'    => $this->getModuleName(),
54
            'NAMESPACE' => $this->getClassNamespace($module),
55
        ]))->render();
56
    }
57
58
    private function getSeederName(): string
59
    {
60
        $end = $this->option('master') ? 'DatabaseSeeder' : 'TableSeeder';
61
62
        return Str::studly($this->argument('name')) . $end;
0 ignored issues
show
Bug introduced by
It seems like $this->argument('name') can also be of type string[]; 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

62
        return Str::studly(/** @scrutinizer ignore-type */ $this->argument('name')) . $end;
Loading history...
63
    }
64
}
65