Completed
Push — master ( 54b42c...81f5ae )
by Nicolas
26:28
created

RouteProviderMakeCommand::getArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 2
cts 2
cp 1
crap 1
rs 9.4285
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Nwidart\Modules\Support\Config\GenerateConfigReader;
6
use Nwidart\Modules\Support\Stub;
7
use Nwidart\Modules\Traits\ModuleCommandTrait;
8
use Symfony\Component\Console\Input\InputArgument;
9
10
class RouteProviderMakeCommand extends GeneratorCommand
11
{
12
    use ModuleCommandTrait;
13
14
    protected $argumentName = 'module';
15
16
    /**
17
     * The command name.
18
     *
19
     * @var string
20
     */
21
    protected $name = 'module:route-provider';
22
23
    /**
24
     * The command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Create a new route service provider for the specified module.';
29
30
    /**
31
     * The command arguments.
32
     *
33
     * @return array
34
     */
35 91
    protected function getArguments()
36
    {
37
        return [
38 91
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
39
        ];
40
    }
41
42
    /**
43
     * Get template contents.
44
     *
45
     * @return string
46
     */
47 3
    protected function getTemplateContents()
48
    {
49 3
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
50
51 3
        return (new Stub('/route-provider.stub', [
52 3
            'NAMESPACE'         => $this->getClassNamespace($module),
53 3
            'CLASS'             => $this->getFileName(),
54 3
            'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'),
55 3
            'MODULE'           => $this->getModuleName(),
56 3
            'ROUTES_PATH'   => $this->getRoutesPath(),
57 3
        ]))->render();
58
    }
59
60
    /**
61
     * @return string
62
     */
63 3
    private function getFileName()
64
    {
65 3
        return 'RouteServiceProvider';
66
    }
67
68
    /**
69
     * Get the destination file path.
70
     *
71
     * @return string
72
     */
73 3
    protected function getDestinationFilePath()
74
    {
75 3
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
76
77 3
        $generatorPath = GenerateConfigReader::read('provider');
78
79 3
        return $path . $generatorPath->getPath() . '/' . $this->getFileName() . '.php';
80
    }
81
82
    /**
83
     * @return mixed
84
     */
85 3
    protected function getRoutesPath()
86
    {
87 3
        return '/' . $this->laravel['config']->get('stubs.files.routes', 'Http/routes.php');
88
    }
89
90 3
    public function getDefaultNamespace() : string
91
    {
92 3
        return $this->laravel['modules']->config('paths.generator.provider.path', 'Providers');
93
    }
94
}
95