RouteProviderMakeCommand::getTemplateContents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 13
rs 9.9666
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Rawilk\LaravelModules\Commands\Generators;
4
5
use Rawilk\LaravelModules\Support\Config\GenerateConfigReader;
6
use Rawilk\LaravelModules\Support\Stub;
7
use Rawilk\LaravelModules\Traits\ModuleCommands;
8
9
class RouteProviderMakeCommand extends GeneratorCommand
10
{
11
    use ModuleCommands;
12
13
    /** @var string */
14
    protected $argumentName = 'module';
15
16
    /** @var string */
17
    protected $signature = 'module:route-provider
18
                            {module? : The name of the module to create the provider for}
19
                            {--force : Force the operation to run when the file already exists}';
20
21
    /** @var string */
22
    protected $description = 'Create a new route provider for the specified module.';
23
24
    protected function getDefaultNamespace(): string
25
    {
26
        /** @var \Rawilk\LaravelModules\Contracts\Repository $module */
27
        $module = $this->laravel['modules'];
28
29
        return $module->config('paths.generator.provider.namespace') ?: $module->config('paths.generator.provider.path', 'Providers');
30
    }
31
32
    protected function getDestinationFilePath(): string
33
    {
34
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
35
36
        $generatorPath = GenerateConfigReader::read('provider');
37
38
        return $path . $generatorPath->getPath() . '/' . $this->getFileName() . '.php';
39
    }
40
41
    protected function getFileName(): string
42
    {
43
        return 'RouteServiceProvider';
44
    }
45
46
    protected function getTemplateContents(): string
47
    {
48
        /** @var \Rawilk\LaravelModules\Module $module */
49
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
50
51
        return (new Stub('/route-provider.stub', [
52
            'NAMESPACE'        => $this->getClassNamespace($module),
53
            'CLASS'            => $this->getFileName(),
54
            'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'),
55
            'MODULE'           => $this->getModuleName(),
56
            'WEB_ROUTES_PATH'  => $this->getWebRoutesPath(),
57
            'LOWER_NAME'       => $module->getLowerName(),
58
        ]))->render();
59
    }
60
61
    private function getWebRoutesPath(): string
62
    {
63
        return '/' . $this->laravel['modules']->config('stubs.files.routes/web', 'routes/web.php');
64
    }
65
}
66