Completed
Pull Request — master (#354)
by Martin
02:17
created

ProviderMakeCommand::getFileName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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