Completed
Pull Request — master (#633)
by
unknown
03:18
created

RouteProviderMakeCommand::getWebRoutesPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
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 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 94
    protected function getArguments()
36
    {
37
        return [
38 94
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
39
        ];
40
    }
41
42
    /**
43
     * Get template contents.
44
     *
45
     * @return string
46
     */
47 86 View Code Duplication
    protected function getTemplateContents()
48
    {
49 86
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
50
51 86
        return (new Stub('/route-provider.stub', [
52 86
            'NAMESPACE'        => $this->getClassNamespace($module),
53 86
            'CLASS'            => $this->getFileName(),
54 86
            'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'),
55 86
            'MODULE'           => $this->getModuleName(),
56 86
            'WEB_ROUTES_PATH'  => $this->getWebRoutesPath(),
57 86
            'API_ROUTES_PATH'  => $this->getApiRoutesPath(),
58 86
            'LOWER_NAME'       => $module->getLowerName(),
59 86
        ]))->render();
60
    }
61
62
    /**
63
     * @return string
64
     */
65 86
    private function getFileName()
66
    {
67 86
        return 'RouteServiceProvider';
68
    }
69
70
    /**
71
     * Get the destination file path.
72
     *
73
     * @return string
74
     */
75 86
    protected function getDestinationFilePath()
76
    {
77 86
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
78
79 86
        $generatorPath = GenerateConfigReader::read('provider');
80
81 86
        return $path . $generatorPath->getPath() . '/' . $this->getFileName() . '.php';
82
    }
83
84
    /**
85
     * @return mixed
86
     */
87 86
    protected function getWebRoutesPath()
88
    {
89 86
        return '/' . $this->laravel['config']->get('stubs.files.routes', 'Routes/web.php');
90
    }
91
92
    /**
93
     * @return mixed
94
     */
95 86
    protected function getApiRoutesPath()
96
    {
97 86
        return '/' . $this->laravel['config']->get('stubs.files.routes', 'Routes/api.php');
98
    }
99
100 86
    public function getDefaultNamespace() : string
101
    {
102 86
        return $this->laravel['modules']->config('paths.generator.provider.path', 'Providers');
103
    }
104
}
105