Passed
Push — master ( 139939...b4b8e8 )
by Arthur
21:54 queued 17s
created

ProviderMakeCommand::getTemplateContents()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 0
dl 0
loc 21
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace Foundation\Generator\Commands;
4
5
use Illuminate\Support\Str;
6
use Nwidart\Modules\Module;
7
use Nwidart\Modules\Support\Config\GenerateConfigReader;
8
use Nwidart\Modules\Support\Stub;
9
use Nwidart\Modules\Traits\ModuleCommandTrait;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputOption;
12
13
class ProviderMakeCommand extends \Nwidart\Modules\Commands\ProviderMakeCommand
14
{
15
    use ModuleCommandTrait;
16
17
    /**
18
     * The name of argument name.
19
     *
20
     * @var string
21
     */
22
    protected $argumentName = 'name';
23
24
    /**
25
     * The console command name.
26
     *
27
     * @var string
28
     */
29
    protected $name = 'module:make-provider';
30
31
    /**
32
     * The console command description.
33
     *
34
     * @var string
35
     */
36
    protected $description = 'Create a new service provider class for the specified module.';
37
38
    public function getDefaultNamespace() : string
39
    {
40
        return $this->laravel['modules']->config('paths.generator.provider.path', 'Providers');
41
    }
42
43
    /**
44
     * Get the console command arguments.
45
     *
46
     * @return array
47
     */
48
    protected function getArguments()
49
    {
50
        return [
51
            ['name', InputArgument::REQUIRED, 'The service provider name.'],
52
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
53
        ];
54
    }
55
56
    /**
57
     * Get the console command options.
58
     *
59
     * @return array
60
     */
61
    protected function getOptions()
62
    {
63
        return [
64
            ['master', null, InputOption::VALUE_NONE, 'Indicates the master service provider', null],
65
        ];
66
    }
67
68
    /**
69
     * @return mixed
70
     */
71
    protected function getTemplateContents()
72
    {
73
        $stub = $this->option('master') ? 'scaffold/provider' : 'provider';
74
75
        /** @var Module $module */
76
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
77
78
        return (new Stub('/' . $stub . '.stub', [
79
            'NAMESPACE'         => $this->getClassNamespace($module),
80
            'CLASS'             => $this->getClass(),
81
            'LOWER_NAME'        => $module->getLowerName(),
82
            'MODULE'            => $this->getModuleName(),
83
            'NAME'              => $this->getFileName(),
84
            'STUDLY_NAME'       => $module->getStudlyName(),
85
            'MODULE_NAMESPACE'  => $this->laravel['modules']->config('namespace'),
86
            'PATH_VIEWS'        => GenerateConfigReader::read('views')->getPath(),
87
            'PATH_LANG'         => GenerateConfigReader::read('lang')->getPath(),
88
            'PATH_CONFIG'       => GenerateConfigReader::read('config')->getPath(),
89
            'MIGRATIONS_PATH'   => GenerateConfigReader::read('migration')->getPath(),
90
            'FACTORIES_PATH'    => GenerateConfigReader::read('factory')->getPath(),
91
        ]))->render();
92
    }
93
94
    /**
95
     * @return mixed
96
     */
97
    protected function getDestinationFilePath()
98
    {
99
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
100
101
        $generatorPath = GenerateConfigReader::read('provider');
102
103
        return $path . $generatorPath->getPath() . '/' . $this->getFileName() . '.php';
104
    }
105
106
    /**
107
     * @return string
108
     */
109
    private function getFileName()
110
    {
111
        return Str::studly($this->argument('name'));
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

111
        return Str::studly(/** @scrutinizer ignore-type */ $this->argument('name'));
Loading history...
112
    }
113
}
114