RouteProviderMakeCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 21
c 1
b 0
f 0
dl 0
loc 55
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultNamespace() 0 6 2
A getWebRoutesPath() 0 3 1
A getDestinationFilePath() 0 7 1
A getTemplateContents() 0 13 1
A getFileName() 0 3 1
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