SeedMakeCommand::getTemplateContents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Consigliere\Components\Commands;
4
5
use Illuminate\Support\Str;
6
use Consigliere\Components\Support\Stub;
7
use Consigliere\Components\Traits\CanClearComponentsCache;
8
use Consigliere\Components\Traits\ComponentCommandTrait;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputOption;
11
12
class SeedMakeCommand extends Command
13
{
14
    use ComponentCommandTrait, CanClearComponentsCache;
15
16
    protected $argumentName = 'name';
17
18
    /**
19
     * The console command name.
20
     *
21
     * @var string
22
     */
23
    protected $name = 'component:make-seed';
24
25
    /**
26
     * The console command description.
27
     *
28
     * @var string
29
     */
30
    protected $description = 'Generate new seeder for the specified component.';
31
32
    /**
33
     * Get the console command arguments.
34
     *
35
     * @return array
36
     */
37
    protected function getArguments()
38
    {
39
        return [
40
            ['name', InputArgument::REQUIRED, 'The name of seeder will be created.'],
41
            ['component', InputArgument::OPTIONAL, 'The name of component will be used.'],
42
        ];
43
    }
44
45
    /**
46
     * Get the console command options.
47
     *
48
     * @return array
49
     */
50
    protected function getOptions()
51
    {
52
        return [
53
            [
54
                'master',
55
                null,
56
                InputOption::VALUE_NONE,
57
                'Indicates the seeder will created is a master database seeder.',
58
            ],
59
        ];
60
    }
61
62
    /**
63
     * @return mixed
64
     */
65
    protected function getTemplateContents()
66
    {
67
        $component = $this->laravel['components']->findOrFail($this->getComponentName());
68
69
        return (new Stub('/seeder.stub', [
70
            'NAME'      => $this->getSeederName(),
71
            'COMPONENT' => $this->getComponentName(),
72
            'NAMESPACE' => $this->getClassNamespace($component),
73
        ]))->render();
74
    }
75
76
    /**
77
     * @return mixed
78
     */
79
    protected function getDestinationFilePath()
80
    {
81
        $this->clearCache();
82
83
        $path = $this->laravel['components']->getComponentPath($this->getComponentName());
84
85
        $seederPath = $this->laravel['components']->config('paths.generator.seed');
86
87
        return $path . $seederPath . '/' . $this->getSeederName() . '.php';
88
    }
89
90
    /**
91
     * Get seeder name.
92
     *
93
     * @return string
94
     */
95
    private function getSeederName()
96
    {
97
        $end = $this->option('master') ? 'DatabaseSeeder' : 'TableSeeder';
98
99
        return Str::studly($this->argument('name')) . $end;
0 ignored issues
show
Bug introduced by
It seems like $this->argument('name') targeting Illuminate\Console\Command::argument() can also be of type array; however, Illuminate\Support\Str::studly() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
100
    }
101
}
102